Python 多输入数字求和

img


😭☔为什么不对呢?球各位帮帮忙,谢谢大家
i want help
thank you very much
please help me

空格改成空字符串

img

Because you're checking a space, not an emply string in your code, which will be an endless loop.
Consider to change ' ' (space) in the if sentence to '' (emply) to stop that.

给写了两种方法:

s = 0
while True:
    n = input()
    if not n:  #即: if n=='':
        break
    s += int(n)
print(s)

#或者:
s = 1
while s:
    try:
        s += int(input())
    except:
        print(s-1)
        break