簡(jiǎn)單的程序獲取用戶(hù)輸入的年份,并確定該年份是否為閏年。不斷返回“中斷”語(yǔ)句的錯(cuò)誤。也許我錯(cuò)過(guò)了一些愚蠢的東西。有什么想法嗎?def is_leap(year):leap = False# Write your logic hereif ((year / 4) % 2== 0) and ((year / 400) % 2 == 0): if ((year / 100) % 2== 0): break else: leap = Truereturn leapyear = int(input())
2 回答
30秒到達(dá)戰(zhàn)場(chǎng)
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
def is_leap(year):
if year%4==0:
if (year%100==0 and year%400!=0):
return False
else:
return True
return False
year = int(input())
print(is_leap(year))
希望這有幫助。
千巷貓影
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
您應(yīng)該使用 代替 .passbreak
break用于停止循環(huán),而不是語(yǔ)句。if
另請(qǐng)參閱:
https://www.tutorialspoint.com/python/python_break_statement.htm
https://www.tutorialspoint.com/python/python_pass_statement.htm
https://www.tutorialspoint.com/python/python_continue_statement.htm
添加回答
舉報(bào)
0/150
提交
取消
