Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于查找闰年而非打印的python用户输入_Python_If Statement_Int_User Input - Fatal编程技术网

用于查找闰年而非打印的python用户输入

用于查找闰年而非打印的python用户输入,python,if-statement,int,user-input,Python,If Statement,Int,User Input,我正在尝试创建一个函数,该函数接受用户输入,并尝试确定该年是否为闰年,然后再接受用户的一年中的哪一天(即355),并将其转换为一年中的哪一天(以及2018年12月10日的输出)。但现在我不确定为什么它不会输出年份是True还是False。我尝试使用int参数将用户输入从字符串更改为数字,但我不确定这是否是我出错的地方 user_year = input('Enter year: ') val = int(user_year) def leap_year(val):

我正在尝试创建一个函数,该函数接受用户输入,并尝试确定该年是否为闰年,然后再接受用户的一年中的哪一天(即355),并将其转换为一年中的哪一天(以及2018年12月10日的输出)。但现在我不确定为什么它不会输出年份是
True
还是
False
。我尝试使用
int
参数将用户输入从字符串更改为数字,但我不确定这是否是我出错的地方

 user_year = input('Enter year: ')
    val = int(user_year)
    def leap_year(val):
        if val % 400 == 0:
            print ("True")
        if val % 100 == 0:
            print ("False")
        if val % 4 == 0:
            print ("True")
        else:
            print ("False")

您只定义了函数
leap\u year
,但从未调用它,下面是一个实际调用该函数的示例:

user_year = input('Enter year: ')
val = int(user_year)

def leap_year(val):
    if val % 400 == 0:
        print ("True")
    if val % 100 == 0:
        print ("False")
    if val % 4 == 0:
        print ("True")
    else:
        print ("False")

leap_year(val)

此外,缩进有点不正确,这会导致它首先无法编译,但复制到Stackoverflow时也可能是一个错误。

您只定义了函数
leap\u year
,但从未调用它,下面是一个实际调用该函数的示例:

user_year = input('Enter year: ')
val = int(user_year)

def leap_year(val):
    if val % 400 == 0:
        print ("True")
    if val % 100 == 0:
        print ("False")
    if val % 4 == 0:
        print ("True")
    else:
        print ("False")

leap_year(val)
此外,缩进有点不正确,这会导致它首先无法编译,但在复制到Stackoverflow时,这也可能是一个错误