我是Python和编程的新手。而且我正在与Zeller的全能一起练习,遇到一天中的问题。我遇到的问题是我似乎无法将/年与其他代码连接/实现。请帮忙。
year = int(input("Year: "))
while year < 1583 or year > 9999:
print("Out of allowed range 1583 - 9999 ")
year = int(input("Year: "))
def leapYear(year):
if year %400 == 0 :
return True
elif year %100 == 0 :
return False
elif year % 4 == 0 :
return True
elif year %4 != 0 :
return False
month = int(input("Month: "))
while month < 1 or month > 12:
print("Out of allowed range 1 – 12 ")
month = int(input("Month: "))
def validDay(year,month,day):
# Months 4, 6, 9, 11 have 30 days
if month == 4 and day >= 31 or 6 and day >= 31 or 9 and day >= 31 or 11 and day >= 31 :
return False
# Month 2 has 28 days, except during a leap year, when it has 29.
elif month == 2 and day < 30 and leapYear is True :
return True
elif month ==2 and day > 28 and leapYear is False:
return False
elif month ==2 and day <= 28:
return True
# Rest have 31 days.
elif day > 31:
print("Out of allowed range 1 - 31 ")
day = int(input("Day: "))
elif day < 32:
return True
if month == 1 or month == 2:
month += 12
year -= 1
day = int(input("Day: "))
while day < 1 or day > 31 :
print("Out of allowed range 1 - 31 ")
day = int(input("Day: "))
if month == 1:
month = month + 12
year = year - 1
elif month == 2:
month = month + 12
year = year - 1
century = (year // 100)
century_year = (year % 100)
weekday = (day + ((26 * (month + 1)) // (10)) + century_year + ((century_year) // \
(4)) + ((century) // (4)) + (5 * century)) % 7
if weekday == 0:
print('It is Saturday')
elif weekday == 1:
print('It is Sunday')
elif weekday == 2:
print('It is Monday')
elif weekday == 3:
print('It is Tuesday')
elif weekday == 4:
print('It is Wednesday')
elif weekday == 5:
print('It is Thursday')
elif weekday == 6:
print('It is Friday')
我如何理解/连接年输入和月输入以及最后输入一天?