-
Notifications
You must be signed in to change notification settings - Fork 0
/
days_in_month.py
63 lines (51 loc) · 1.18 KB
/
days_in_month.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
"""
100 days of Python course
DAY 10
"""
def is_leap(year):
"""
Parameters
----------
year : TYPE
DESCRIPTION.
Returns
-------
bool
DESCRIPTION.
"""
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False
def days_in_month(year, month):
"""
Parameters
----------
year : TYPE
DESCRIPTION.
month : TYPE
DESCRIPTION.
Returns
-------
TYPE
DESCRIPTION.
"""
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if month > 12 or month < 1:
return "Invalid month entered."
if month == 2 and is_leap(year):
return 29
return month_days[month - 1]
year = int(input("Enter a year (numeric): "))
month = int(input("Enter a month (numeric): "))
days = days_in_month(year, month)
print(days)
# note that refactor and warning messages generated by pylint
# which are outside the scope of this lesson: the program runs
# without errors