def month_date_valid(month):
if month > 0 and month <= 12:
return True
else:
return false
def get_day_count(month, days):
list1 = [1,3,5,7,8,10,11]
list2 = [2,4,6,9,]
count = 0
for i in range(1, month):
if i in list1:
count+31
elif i in list2:
count+30
else:
count+= 28
return count + days
list1 = [1,3,5,7,8,10,11]
list2 = [2,4,6,9,]
for i in range(1,13):
if i in list1:
for j in range(1, 30):
answer = get_day_count(i,j)
print((i, j), 'is', answer)
elif i in list2:
for j in range(1, 31):
answer = get_day_count(i, j)
print((i, j), 'is', answer)
else:
for j in range(1,29):
answer = get_day_count(i, j)
print((i, j), 'is', answer)
def main():
month = int(input('Enter the month of the year: '))
day = int(input('Enter the day of the year: '))
if month_date_valid(month):
month = (get_day_count(month, day))
return True
else:
print('Month in invalid, try again')
我哪里出错了,因为它是假设要求我输入月份和日期,看看月份和日期是否有效?我真的卡住了,需要帮助快。任何想法欢迎。
1条答案
按热度按时间toe950271#
你定义了一个
main()
函数,但是你从来没有调用过它。Python不会自动为你调用main()
,这与其他一些语言不同。