Input validation 2nd step in 2nd unit of Intro to computer science-Python
Amy tests her form by entering 6 for the month and 31 for the day. What bug does she find?
June 31 should be an invalid date, because April, June, September, and November only have 30 days. She needs to validate the day and month in combination!
-
Add a conditional that checks if the day is 31 for the months with only 30 days.
-
If the combination is invalid, print the message:
Error. Day must be within the month.
Pay attention to your compound condition's order of operations - you may need parentheses here! You can ignore February for now.
Make sure to print the exact error message provided.
This is the problem given and this is the answer and i got the displayed output but do you know any other way i which it might accept??
i wrote this code
day = int(input("Enter a day (1-31): "))
if day < 1 or day > 31:
print("Error. Day must be between 1 and 31.")
month = int(input("Enter a month (1-12): "))
if month < 1 or month > 12 :
print("Error. Month must be between 1 and 12.")
if month == 4 or month == 6 or month == 9 or month == 11 and (day > 30):
print('Error. Day must be with month')
Vous devez vous connecter pour laisser un commentaire.