2017-04-04 43 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