我试图确定这些年是否是闰年。 1900,1999,2000,2001,2002,2003,2004
def leapyr(n):
if (n%4==0) and (n%100!=0):
if (n%400==0):
print (n, " is a leap year.")
elif (year%4!=0):
print (n, " is not a leap year.")
numbers = [(1900),(1999),(2000),(2002),(2003),(2004),]
results=[]
for x in numbers:
print(leapyr(numbers))
这是我得到的错误:
Traceback (most recent call last):
File "C:/Users/gx2410ls/hw 12.py", line 13, in <module>
print(leapyr(numbers))
File "C:/Users/gx2410ls/hw 12.py", line 2, in leapyr
if (n%4==0) and (n%100!=0):
TypeError: unsupported operand type(s) for %: 'list' and 'int'
答案 0 :(得分:0)
您传递了错误的值。使用
print(leapyr(x))