-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_month_year_validate.py
More file actions
40 lines (35 loc) · 1.16 KB
/
date_month_year_validate.py
File metadata and controls
40 lines (35 loc) · 1.16 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
# validate the input year, month and day and give the output date without using datetime module.
months={1:31,2:{'leap':29,'notleap':28},3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
year=eval(input("enter year"))
# check for leap year or not
def check_for_leap(year):
if (year%100!=0 and year%2==0) or (year%400==0):
leap_year= 'leap'
else:
leap_year= 'notleap'
return leap_year
# print(leap_year)
ver=True
while ver:
month = eval(input('enter a month from 1 to 12'))
if month in range(1,13):
ver=False
else:
print('Enter valid month')
leap_year= check_for_leap(year)
val=True
while val:
day = eval(input("enter a day"))
if month!=2:
print(months[month])
if day not in range(1,months[month]+1):
print("enter a valid day")
else:
val=False
else:
print(months[month][leap_year])
if day in range(1,months[month][leap_year]+1):
val=False
else:
print('enter a valid day')
print("date in format of day,month,year is {}/{}/{}".format(day,month,year))