修改一个:months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
months_leap = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
while True:
year = int(input('year:\n'))
if 0 < year < 9999:
break
else:
print('year error.')
while True:
month = int(input('month:\n'))
if 0 < month < 13:
break
else:
print('month error.')
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
leap = 1
else:
leap = 0
while True:
day = int(input('day:\n'))
if leap:
if 0 < month <= months_leap[month - 1]:
break
else:
if 0 < month <= months[month - 1]:
break
print('day error.')
if leap:
days = sum(months_leap[:month - 1]) + day
else:
days = sum(months[:month - 1]) + day
print ('it is the %dth day.' % days)
|