I have an error and I think why the teacher doesn’t use else in the code below.
def is_leap(year):
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():
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if is_leap(year) and month == 2:
return 29
else:
return month_days[month-1]
#🚨 Do NOT change any of the code below
year = int(input("Enter a year: "))
month = int(input("Enter a month: "))
days = days_in_month(year, month)
print(days)
I got this error. I was checking and I have the same teacher but I still get this error.
Enter a month: 2
Traceback (most recent call last):
File "main.py", line 22, in <module>
days = days_in_month(year, month)
TypeError: days_in_month() takes 0 positional arguments but 2 were given
>Solution :
You pass two arguments into days_in_month, even though it is a function that doesn’t take in any arguments.
The function signature for days_in_month should be:
def days_in_month(year, month):