Write a program that asks the user to enter a month 1 for January 2 for February and so on and then prints the number of days in the month For February print 28 or 29 days Enter a month 5 30 days Do
month = int(input("Enter a month (1-12): "))
check if month has 30 days
has_30_days = month == 4 or month == 6 or month == 9 or month == 11
check if month has 31 days
has_31_days = month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12
if has_30_days: print("30 days") elif has_31_days: print("31 days") else: year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print("29 days") else: print("28 days")
原文地址: https://www.cveoy.top/t/topic/boZu 著作权归作者所有。请勿转载和采集!