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 a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
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...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest common divisor. *I am using Eclipse DS-5 Community Workspace with A64 Instruction Set) Use the following algorithm: // Given two integers m and n: if (m < n) gcd(n, m) if n is a divisor of m gcd(m, n) = n else gcd (m, n) = gcd (n, m % n) Your program must be recursive. You must create a function that calls itself,...
In python write a program that gets a list of integers from input, and outputs non-negative...
In python write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space. Do not end with newline
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT