编写一个程序,提示用户输入一个月和一年,然后输出一条消息 说明给定月份的天数(注意:如果用户,您需要考虑闰年 进入2月份的月份)
if(year / 400 == 0)and(year / 100!= 0)或(year / 4 == 0):
print( "this year is a leap year: ")
if ( month == "December" or month == "January" or month == "March" or month == "May" or month == "July" or month == "August" or month == "October" ):
print ("days are: 31")
elif ( month == "April" or month == "June" or month == "September" or month == "November"):
print ("days are: 30")
elif ( month == "February" ):
print ("days are: 29")
否则:
print( "this year is not a leap year: ")
if ( month == "December" or month == "January" or month == "March" or month == "May" or month == "July" or month == "August" or month == "October" ):
print ("days are: 31")
elif ( month == "April" or month == "June" or month == "September" or month == "November"):
print ("days are: 30")
elif ( month == "February" ):
print ("days are: 28")
代码不正确,它只能与else一起使用,所以如果有人对错误有所了解 我认为第一个条件中的错误(如果年/ 400 == 0).......
答案 0 :(得分:1)
答案 1 :(得分:0)
使用这样的辅助函数:
def is_leap(n):
if n % 400 == 0:
return True
if n % 100 == 0:
return False
if n % 4 == 0:
return True
else:
return False
if is_leap(year):
#your code
答案 2 :(得分:-2)
看看年份是否可被4整除。如果是这样,那就是闰年。
if not year % 4:
leap_year = True