中断语句问题

简单的程序获取用户输入的年份,并确定该年份是否为闰年。不断返回“中断”语句的错误。也许我错过了一些愚蠢的东西。有什么想法吗?


def is_leap(year):

leap = False


# Write your logic here

if ((year / 4) % 2== 0) and ((year / 400) % 2 == 0):

    if ((year / 100) % 2== 0):

        break

    else:

        leap = True

return leap


year = int(input())


翻阅古今
浏览 127回答 2
2回答

30秒到达战场

def is_leap(year): if year%4==0:    if (year%100==0 and year%400!=0):        return False    else:        return True return Falseyear = int(input())print(is_leap(year))希望这有帮助。

千巷猫影

您应该使用 代替 .passbreakbreak用于停止循环,而不是语句。if另请参阅:https://www.tutorialspoint.com/python/python_break_statement.htmhttps://www.tutorialspoint.com/python/python_pass_statement.htmhttps://www.tutorialspoint.com/python/python_continue_statement.htm
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python