Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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 While循环中的输入函数_Python_Function_Input_While Loop - Fatal编程技术网

Python While循环中的输入函数

Python While循环中的输入函数,python,function,input,while-loop,Python,Function,Input,While Loop,在这个程序中,我试图使while循环中的变量integer_enter一直被赋值为整数,直到在输入中输入0为止。每次运行代码时,“integer\u enter=int(input())”行上都会出现EOF错误。为什么会这样?在while循环中定义一个变量并没有什么错,为什么会出现这样的错误呢 参考代码: list_num = [ ] count_even = 0 loop_condition= True while(loop_condition == True): integer_

在这个程序中,我试图使while循环中的变量integer_enter一直被赋值为整数,直到在输入中输入0为止。每次运行代码时,“integer\u enter=int(input())”行上都会出现EOF错误。为什么会这样?在while循环中定义一个变量并没有什么错,为什么会出现这样的错误呢

参考代码:

list_num = [ ]
count_even = 0

loop_condition= True

while(loop_condition == True):
    integer_enter= int(input())
    integer_append= list_num.append(integer_enter)
    if(integer_enter % 2 == 0):
        count_even += 1
    elif(integer_enter == 0):
        loop_condition = False 




print('The number of even integers is %d' % count_even)

print(list_num)

您需要修改循环终止的条件。当输入的
整数为
0
时,需要确保未执行
if
。是指向代码的工作链接

list_num = [ ]
count_even = 0

loop_condition= True

while(loop_condition == True):
    integer_enter= int(input())
    integer_append= list_num.append(integer_enter)
    if(integer_enter % 2 == 0 and integer_enter != 0):
        count_even += 1
    elif(integer_enter == 0):
        loop_condition = False 




print('The number of even integers is %d' % count_even)

print(list_num)

while循环永远不会停止,因为只有当输入的整数等于正数时,
0%2==0
才会停止,对吗?顺便说一句,
integer\u append为None
将始终为真,因为
list.append
不会返回任何内容。谢谢。我忘了0%2也等于0。