# Functions to make sure the user gives us a valid date. # Check to make sure year is in the right range. def validYear(year): if year >= 1500 and year <= 2400: return True else: return False # Check to make sure month is in the right range def validMonth(month): return month >= 1 and month <= 12 # Return True is year is a leap year. def leapYear(year): return False # Check the validity of the day, given the month and year. def validDay(month,day,year): # Months 4, 6, 9, 11 have 30 days # Month 2 has 28 days, except during a leap year, when it has 29. # Rest have 31 days. return True # Top level function for getting a valid date. def getValidDate(): month = int(input("Please enter a valid month (1-12): ")) day = int(input("Please enter a valid day (1-31): ")) year = int(input("Please enter a valid year (1500-2400): ")) # Data validation loops to make sure these values are valid # and to fix them if they're not. while not validMonth(month): print("Month: ", month, " is not between 1 and 12.") month = int(input("Please enter a valid month (1-12): ")) while not validYear(year): print("Year: ", year, " is not between 1500 and 2400.") year = int(input("Please enter a valid year (1500-2400): ")) while not validDay(month,day,year): print("Day is not valid for this month and year.") day = int(input("Please enter a valid day (1-31): ")) return month, day, year