In: Computer Science
Writing a Modular Program in Python
In this lab, you add the input and output statements to a partially
completed Python program. When completed, the user
should be able to enter a year, a month, and a day. The program
then determines if the date is valid. Valid years are those that
are greater than 0, valid months include the values 1 through 12,
and valid days include the values 1 through 31.
Instructions
month/day/year is a valid date.or
month/day/year is an invalid date.
month = 5, day = 32 year = 2014
month = 9 day = 21 year = 2002
Python 3 code
============================================================================================
year=int(input('Enter year: '))
month=int(input('Enter month: '))
day=int(input('Enter day: '))
f=1
if(year<=0):
f=0
elif(month<1 or month>12):
f=0
elif(day<1 or day>31):
f=0
if f==1:
print(month,'/',day,'/',year,' is a valid date.')
else:
print(month,'/',day,'/',year,' is an invalid date.')
============================================================================================
Output