我正在做一個程序來計算,如果給定的輸入是一個閏年或沒有。我在使用Anaconda Shell的Windows 10上使用Python 2.7。 這是一個愚蠢的程序,我不明白爲什麼我得到這個錯誤。這個特定的程序有幾個解決方案在線,但我想讓我的版本工作。請幫忙!「詮釋」對象不能迭代閏年程序
我收到錯誤消息「TypeError:'int'object is not iterable」 我試着用Google搜索一些東西並查看一些以前的答案,但是我很困惑!
def sort_year(user_input):
for i,j in range(0,9):
if user_input == [ij00]:
leap_yr1(user_input)
else:
leap_yr2(user_input)
def leap_yr1(user_input):
if user_input % 400 == 0:
print("The given year is a leap year")
else:
print("The given year is not a leap year")
def leap_yr2(user_input):
if user_input % 4 == 0:
print("The given year is a leap year")
else:
print("The given year is not a leap year")
print("Which year do you want to check?: ")
user_input = int(raw_input())
sort_year(user_input)
您正在試圖解開的'範圍(0,9)'作爲2元組的每個值。你期望'ij00'做什麼? – vaultah
公平起見,'int'對象不可迭代*任何*程序,閏年或其他。 – jonrsharpe
你*寫*:如果年%4!= 0:返回false:elif year%100!= 0:返回true:else return year%400 == 0'而不是有兩個函數。 - 雖然這不是你的問題。 –