Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question1 Write function season ( that takes as input the number of a month (1-1

ID: 3716176 • Letter: Q

Question

Question1 Write function season ( that takes as input the number of a month (1-12), write the answer to a file called season.txt, and prints the season corresponding to the month. If the number provided is not in the 1-12 range, then print 'Invalid input!'message and write the same message to season.txt. You may assume that numbers 1 to 3 correspond to Winter, 4 to 6 correspond to Spring, 7 to 9 correspond to Summer, and 10 to 12 correspond to Fall. The following shows the behavior of the function for some sample parameters. >>>season (1) Winter >>season (10) Fall >>>season (13) Invalid input! >>> season (0) Invalid input!

Explanation / Answer

def season(month):

file=open("season.txt","w")

if(month<1 or month>12):

print 'Invalid Input!'

file.write("Invalid Input! ")

else:

if(month>=1 and month<=3):

file.write("Winter ")

else:

if(month>=4 and month<=6):

file.write("Spring ")

else:

if(month>=7 and month<=9):

file.write("Summer ")

else:

file.write("Autumn ")

file.close()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote