Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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 3.x 如何打破我的循环?_Python 3.x_Loops - Fatal编程技术网

Python 3.x 如何打破我的循环?

Python 3.x 如何打破我的循环?,python-3.x,loops,Python 3.x,Loops,我想让循环将整数添加到列表中,并在用户点击return时将中断 我如何做到这一点 lstScore = [] count = 0 while count >= 0: count = int(input("Enter a score :")) if count != int: break elif: lstScore.append(int(count)) 这将帮助您,为int转换错误添加异常处理 lstScore = [] c

我想让循环将
整数
添加到列表中,并在用户点击return时将
中断

我如何做到这一点

lstScore = []
count = 0

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

这将帮助您,为int转换错误添加异常处理

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

是否希望在用户按下返回键时结束?