Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.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 即使用户输入了0,列表仍将继续打印_Python_Python 2.7_Input_Type Conversion - Fatal编程技术网

Python 即使用户输入了0,列表仍将继续打印

Python 即使用户输入了0,列表仍将继续打印,python,python-2.7,input,type-conversion,Python,Python 2.7,Input,Type Conversion,即使用户输入的输入值为0,列表也不会退出。您的输入值是字符串而不是数字 尝试将其转换为整数或将其转换为整数 试试这个 end = False numbers = [] while not end: i =(raw_input(" Enter the number(0 to end the input)")) if i ==0: end = True else: numbers.append(i) print numbers 或者把你的意见作为 if int(i) == 0

即使用户输入的输入值为0,列表也不会退出。您的输入值是字符串而不是数字

尝试将其转换为整数或将其转换为整数

试试这个

end = False
numbers = []
while not end:
 i =(raw_input(" Enter the number(0 to end the input)")) 
 if i ==0:
  end = True
 else:
  numbers.append(i)
 print numbers
或者把你的意见作为

if int(i) == 0
i =(input(" Enter the number(0 to end the input)"))