【问题标题】:List keep on printing even when 0 was entered by the user即使用户输入了 0,列表也会继续打印
【发布时间】:2017-12-11 08:39:08
【问题描述】:
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

即使用户输入的输入为0,列表也不退出

【问题讨论】:

    标签: python python-2.7 input type-conversion


    【解决方案1】:

    你得到你的字符串而不是数字..

    尝试将其转换为整数或将其作为整数获取

    试试这个,

    if int(i) == 0
    

    或将您的输入设为 ,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多