-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.13.py
118 lines (111 loc) · 3.15 KB
/
7.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def DayofYear(date):
month = int(date[:2])
day = int(date[3:5])
year = int(date[6:10])
dayNum = 0
if dateValidator(date) == True:
if LeapYear(year) == True and month >= 3:
dayNum = (31 * (month - 1) + day) - ((4 * month + 23)//10) + 1
elif month >= 3:
dayNum = (31 * (month - 1) + day) - ((4 * month + 23)//10)
else:
dayNum = (31 * (month - 1) + day)
return dayNum
def LeapYear(year):
status = False
if year % 100 == 0 and year % 400 == 0:
status = True
elif year % 100 == 0 and year % 400 != 0:
status = False
elif year % 4 == 0:
status = True
else:
status = False
return status
def dateValidator(date):
month = int(date[:2])
day = int(date[3:5])
year = int(date[6:10])
status = False
if 1 <= year:
if month == 1:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 2:
if LeapYear(year) == True and 1 <= day <= 29:
status = True
elif LeapYear(year) == False and 1 <= day <= 28:
status = True
else:
status = False
if month == 3:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 4:
if 1 <= day <= 30:
status = True
else:
status = False
if month == 5:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 6:
if 1 <= day <= 30:
status = True
else:
status = False
if month == 7:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 8:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 9:
if 1 <= day <= 30:
status = True
else:
status = False
if month == 10:
if 1 <= day <= 31:
status = True
else:
status = False
if month == 11:
if 1 <= day <= 30:
status = True
else:
status = False
if month == 12:
if 1 <= day <= 31:
status = True
else:
status = False
return status
def main():
print()
print("This app tells you the number of the day in a year.\n")
D = input("What's the date? Enter as mm/dd/yyyy\n\n")
try:
print("The day of the year is {}".format(DayofYear(D)))
except ValueError:
print("\nThe numbers you entered weren't quite right…")
except NameError:
print("\nOnly numbers please.")
except TypeError:
print("\nThe numbers you entered weren't quite right…")
except SyntaxError:
print("\nType it correctly next time buddy.")
except:
print("\nGeneral error. Terribly sorry.")
print()
main()