Question

In: Computer Science

Write a program in python that takes a date as input and outputs the date's season....

Write a program in python that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.

Ex: If the input is:

April
11

the output is:

Spring

In addition, check if the string and int are valid (an actual month and day).

Ex: If the input is:

Blue
65

the output is:

Invalid 

The dates for each season are:
Spring: March 20 - June 20
Summer: June 21 - September 21
Autumn: September 22 - December 20
Winter: December 21 - March 19

Solutions

Expert Solution

if __name__ == '__main__':
    inputMonth = input()
    inputDay = int(input())

    if inputMonth == "January" and 1 <= inputDay <= 31:
        print("Winter")
    elif inputMonth == "February" and 1 <= inputDay <= 29:
        print("Winter")
    elif inputMonth == "April" and 1 <= inputDay <= 30:
        print("Spring")
    elif inputMonth == "May" and 1 <= inputDay <= 30:
        print("Spring")
    elif inputMonth == "July" and 1 <= inputDay <= 31:
        print("Summer")
    elif inputMonth == "August" and 1 <= inputDay <= 31:
        print("Summer")
    elif inputMonth == "October" and 1 <= inputDay <= 31:
        print("Autumn")
    elif inputMonth == "November" and 1 <= inputDay <= 30:
        print("Autumn")
    elif inputMonth == "March" and 20 <= inputDay <= 31:
        print("Spring")
    elif inputMonth == "June" and 1 <= inputDay <= 20:
        print("Spring")
    elif inputMonth == "June" and 21 <= inputDay <= 30:
        print("Summer")
    elif inputMonth == "September" and 1 <= inputDay <= 21:
        print("Summer")
    elif inputMonth == "September" and 22 <= inputDay <= 30:
        print("Autumn")
    elif inputMonth == "December" and 0 <= inputDay <= 20:
        print("Autumn")
    elif inputMonth == "December" and 21 <= inputDay <= 30:
        print("Winter")
    elif inputMonth == "March" and 1 <= inputDay <= 19:
        print("Winter")
    else:
        print("Invalid")


Related Solutions

Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring:...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT