typeError:%支持的操作数类型:' list'和' int'

时间:2017-11-30 03:20:38

标签: python list leap-year

我试图确定这些年是否是闰年。 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'

1 个答案:

答案 0 :(得分:0)

您传递了错误的值。使用

print(leapyr(x))