forked from Manish57-droid/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar_day.py
116 lines (106 loc) · 2.75 KB
/
calendar_day.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
#Python code to find day at which a particular date occurs
import calendar
def isleap(y):
if y%100==0:
if y%400==0:
return True
else:
return False
else:
if y%4==0:
return True
else:
return False
def valid_dates(d,m,y,l):
#if it is leap year
if l:
if m==2:
if d<30:
return True
else:
return False
#for months until July
elif m<8:
if m%2==0:
if d<31:
return True
else:
return False
else:
if d<32:
return True
else:
return False
#for months onwards August
else:
#even months
if m%2==0:
if d<32:
return True
else:
return False
else:
if d<31:
return True
else:
return False
else:
if m==2:
if d<30:
return True
else:
return False
#for months until July
elif m<8:
if m%2==0:
if d<31:
return True
else:
return False
else:
if d<32:
return True
else:
return False
#for months onwards August
else:
#even months
if m%2==0:
if d<32:
return True
else:
return False
else:
if d<31:
return True
else:
return False
def get_day(day_index):
days_of_week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
return days_of_week[day_index]
#inputting year
while(1):
year = int(input("Enter year: "))
if year<1970:
print("Enter years only after 1970.")
else:
break
leap = isleap(year)
#inputting month
while(1):
month = int(input("Enter month: "))
if month>0 and month<13:
break
else:
print("Enter correct month number.")
#inputting date
while(1):
date = int(input("Enter date: "))
if date>0 and valid_dates(date,month,year,leap):
break
else:
print("Enter valid date.")
day_index = calendar.weekday(year,month,date)
day = get_day(day_index)
#final output
print(date,"/",month,"/",year,"lies on",day)