关于try except break语句如何使用

1.这种含数字(int、float)类型的输入,怎么使用break来主动终止循环的运行,我使用的这个输入done是没有用的

count=0
total=0
shu=0
while True:
    try:
        shu=float(input('shu'))
    except:
        print('error')
    if  shu=='done':
        break
for i in [shu]:
    count+=1
    total+=i
    print(count,total,total/count)

2.try 和 except中间应放可能出错的代码吗

img

你好同学,需要指定异常值处理办法:

count=0
total=0
shu=[]
while True:
    try:
        shustr = input('shu')
        shu.append(float(shustr))
    except:
        if shustr=='done': #如果异常值是
            break
        else:
            print('error')
for i in shu:
    count+=1
    total+=i
print(count,total,total/count) # 输出

示例:

shu 1
shu 2
shu 3
shu 4
shudone
4 10.0 2.5

如有帮助,还望题主给个采纳支持一下答主答题哟,十分感谢(づ ̄3 ̄)づ╭❤~