-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexercise_13.py
54 lines (51 loc) · 1.37 KB
/
exercise_13.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#accepts date
#verifies it
#calculates day number
def leapYear(year):
if (year % 4) != 0:
return False
else:
if (year % 100) == 0:
if (year % 400) ==0:
return True
else:
return False
else:
return True
def verDate(month, day, year):
if month > 12 or day > 31:
return False
else:
if day <= 28:
return True
elif month == 2 and day == 29:
if leapYear(year) == False:
return False
else:
return True
elif day == 31:
if month == 2 or 4 or 6 or 11:
return False
else:
return True
else:
return True
def main():
dateStr = '05/25/1885'
monthStr, dayStr, yearStr = dateStr.split("/")
month = int(monthStr)
day = int(dayStr)
year = int(yearStr)
if verDate(month, day, year) == False:
print("This date is invalid.")
else:
dayNum = 31 * (month - 1) + day
if month == 2:
if leapYear(year) == True:
dayNum = dayNum - (4 * (month) + 23)//10 + 1
else:
dayNum = dayNum - (4 * (month) + 23)//10
else:
dayNum = 31 * (month - 1) + day
print("The numeric value of this date is {}.".format(dayNum))
main()