Why is Python making a mistake?
-
I'm trying to do different tasks for the python, doing this.To write a function of a date that takes 3 arguments - day, month and year. Get True back if that date is in our calendar, and False is different."
I want to accomplish this task so (code )
def date(day, month, year): if year % 2 == 1: # Проверяем год, на високосность if month <= 12: # Проверяем месяц, правильное ли количество месяцев if month != 2: if month % 2 == 0: # Проверяем месяц, (30 или 31 дней) if day <= 30: # Проверяем день на правильность их количества в месяце return True elif month == 2: elif: else: return False
else: return False
elif year % 2 == 0:
elif month <= 12:
elif month == 2:
elif month % 2 == 0:
elif day <= 29:
return True
else:
return False
else:
return Falsedate(10, 5, 2021)
Makes a mistake: "File "MY WAY," line 7
return True
TabError: inconsistent use of tabs and spaces in indentation."♪ I didn't find a tabulation error. That's why I can't do it.
-
I suggest that we look towards the solution using the datetime module:
from datetime import date
def check_date(y, m, d):
try:
date(y, m, d) # Проверяем получается ли дата из наших значений
return True
except:
return Falseprint(check_date(2018, 2, 28)) # True, есть в календаре
print(check_date(2018, 2, 29)) # False, нет в календаре