-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendar.py
More file actions
127 lines (114 loc) · 3.08 KB
/
Calendar.py
File metadata and controls
127 lines (114 loc) · 3.08 KB
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
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 17:48:14 2020
@author: Nikhil Bhargava
Calendar using Python
"""
import calendar
def CheckLeap(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 CheckValidDate(dt, mo, yr, leap):
if(leap):
if mo==2: #February
if dt<30:
return True
else:
return False
else:
if mo<8:
if mo%2==1:
if dt<32:
return True
else:
return False
else:
if dt<31:
return True
else:
return False
else:
if mo%2==0:
if dt<32:
return True
else:
return False
else:
if dt<31:
return True
else:
return False
else:
if mo==2: #February
if dt<29:
return True
else:
return False
else:
if mo<8:
if mo%2==1:
if dt<32:
return True
else:
return False
else:
if dt<31:
return True
else:
return False
else:
if mo%2==0:
if dt<32:
return True
else:
return False
else:
if dt<31:
return True
else:
return False
def GetDay(day_index):
days=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
return(days[day_index])
'''
Main
'''
flag=True
#Takea valid year
while (flag==True):
year=int(input("Enter year (1978-2020): "))
if(year<1978):
print("Enter a valid year b/w 1978 till 2020")
flag=True
else:
flag=False
flag=True
#Takea valid month
while (flag==True):
month=int(input("Enter month (1-12): "))
if( (month<0) or (month>12) ):
print("Enter a valid month b/w 1 to 12")
flag=True
else:
flag=False
leap=CheckLeap(year)
flag=True
#Takea valid date
while (flag==True):
date=int(input("Enter date (1-31): "))
if date >0 and CheckValidDate(date, month, year, leap):
flag=False
else:
flag=True
day_index=calendar.weekday(year,month,date)
day=GetDay(day_index)
print("\n")
print(date,"/",month,"/",year,"falls on", day)