|
发表于 2017-5-30 21:01:41
|
显示全部楼层
代码多了点,但是排除了所有输入错误的情况,所有输入错的数值都要重新输入
- a = input ("please enter the year:")
- while a.isdigit()!= True:
- a = input ("ERROR! Please enter the year again:")
- yy = int (a)
- if yy % 4 != 0:
- r = 1
- elif (yy % 400 == 0) or (yy % 100 != 0):
- r = 2
- elif yy % 100 == 0:
- r = 1
- b = input ("please enter the month:")
- b1 = ['1','2','3','4','5','6','7','8','9','10','11','12']
- while b not in b1:
- b = input ("ERROR! please enter the month again:")
- mm = int (b)
- if r == 1:
- month = [31,28,31,30,31,30,31,31,30,31,30,31]
- else:
- month = [31,29,31,30,31,30,31,31,30,31,30,31]
- day = month[mm-1]
- i = 1
- day1 = []
- while i<=day:
- temp = str(i)
- day1.append (temp)
- i += 1
- c = input ("please enter the day:")
- while c not in day1:
- c = input ("ERROR! please enter the day again:")
- dd = int (c)
- n = 0
- while mm != 1:
- n += month[mm-2]
- mm -= 1
- n += dd
- print (n)
复制代码 |
|