Question: Python. Please advise. Thank you in advance. I'm using (well, trying to) elif statements to attempt to write this and am not sure how to
Python. Please advise. Thank you in advance.
I'm using (well, trying to) elif statements to attempt to write this and am not sure how to proceed. Here are the assignment requirements:
Must check for valid day and month. (3 points) For e.g. if month is 4 then day can not be 31. (3 points) If it is a leap year, day can be 29 for month of February. (3 points) Allow the user to enter a year between 1900 and 2030. Verify it is in this range only. Use the last 2 digits of the year entered for determining if it is a magic date or not, Use the 4 digit year to determine leap or not. Hint: You can you use the '%' operator to find the right two digits of the year. See Table 2-3. Prints an appropriate response. (6 points) Include various years such as 2000, 1980 etc. which are leap years and not leap years in testing to verify your program functions correctly. Include the output as comments in your program. Check for LEAP year: If the year is evenly divisible by 400 to confirm a leap year. If a year is divisible by 100, but not 400, then it is not a leap year.
This is what I have so far but am confused by the elif statements and keep getting syntax errors.
month = int(input('Please enter a month as a number: '))
day = int(input('Please enter a day as a number: '))
year = int(input('Please enter a year as a four-digit number: '))
if month>=1 and month<=12:
day = int(input('Please enter a day as a number: '))
if (day>=1 and day <=31) and year >=1900 and year<=2030:
elif (month==1) and (day>=1 and day<=31):
elif (month ==2) and (day>=1 and day<=29):
elif (month==3) and (day>=1 and day<=31):
elif (month==4) and (day>=1 and day<=30):
elif (month==5) and (day>=1 and day<=31):
elif (month==6) and (day>=1 and day<=30):
elif (month==7) and (day>=1 and day<=31):
elif (month==8) and (day>=1 and day<=31):
elif (month==9) and (day>=1 and day<=30):
elif (month==10) and (day>=1 and day<=31):
elif (month==11) and (day>=1 and day<=30):
elif (month==12) and (day>=1 and day<=31):
else print('Error. Please enter a different date.')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
