Write a function daysInMonth(month, year)
The function receives two integers: month as a first parameter and year as a second parameter.
If month is a February, the function checks if the current year is a leap year to determine how many days February contains.
For the remaining months year check up is not required.
In order to find out whether the year is leap, use function that you defined for the Problem 1 solution.
If year is not provided, the default value 2022 should be assigned to the year automatically.
def daysInMonth(month, year=2022):
list1 = ['september', 'april', 'june', 'november']
list2 = ['january', 'march', 'may', 'july', 'august', 'october', 'december']
if month.lower() == 'february':
if year % 4 == 0:
return 29
else:
return 28
elif month.lower() in list1:
return 30
elif month.lower() in list2:
return 31
daysInMonth('February')
28
Comments
Leave a comment