Skip to content

Commit 1013341

Browse files
authored
Create month
1 parent 7931dd7 commit 1013341

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

month

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Write a function that determines how many days there are in a particular month. Your function will take
2+
two parameters: The month as an integer between 1 and 12, and the year as a four-digit integer. Ensure
3+
that your function reports the correct number of days in February for leap years. Include a main program
4+
that reads a month and year from the user and displays the number of days in that month.
5+
6+
-
7+
8+
month = int(input('Please enter a month in the form of digit : '))
9+
10+
if month in (1, 3, 5, 7, 8, 10, 12):
11+
days = 31
12+
13+
year = int(input('Please enter the year : '))
14+
print('Number of days in month %d in year %d is %d' % (month, year, days))
15+
16+
elif month in (4, 6, 9, 11):
17+
days = 30
18+
19+
year = int(input('Please enter the year : '))
20+
print('Number of days in month %d in year %d is %d' % (month, year, days))
21+
22+
elif month == 2:
23+
24+
year = int(input('Please enter the year : '))
25+
if (year % 4 == 0) and (not(year % 100 == 0) or (year % 400 == 0)):
26+
days = 29
27+
else:
28+
days = 28
29+
print('Number of days in month %d in year %d is %d' % (month, year, days))
30+
31+
else:
32+
print('You insert an invalid month')

0 commit comments

Comments
 (0)