2017-04-04 49 views
0

我想要循环添加integers到列表和break当用户点击返回。如何打破我的循环?

我该如何设法做到这一点?

lstScore = [] 
count = 0 

while count >= 0: 
    count = int(input("Enter a score :")) 
    if count != int: 
     break 
    elif: 
     lstScore.append(int(count)) 
+0

你想让它当用户按下回车键结束INT转换错误? – eyllanesc

回答

0

这会帮助你,加入异常处理

lstScore = [] 
count = 0 

while count >= 0: 
    try: 
     temp = input("Enter a score :") 
     if(temp != ''): 
      count = int(temp) 
     else: 
      break 
     lstScore.append(int(count)) 
    except ValueError as x: 
     print("value error") 
     break