我需要一些帮助程序的逻辑。我在做什么:逻辑问题 - 数字总和
用一个循环编写程序,要求用户输入一系列正数。 用户应该输入一个负数来表示该系列的结尾。在输入所有正数 数字后,程序应显示总和。
keep_going = ' '
max =()
total = 0.0
print('This program will add numbers together until a negative number is entered.')
print('It will then show the total of the numbers entered.')
while keep_going != (-):
number = int(input('Enter a number: '))
total = total + number
print('The total is', total)
我哪里错了?
total = 0
while True:
number = int(input('Enter a number: '))
if number < 0:
break
total = total + number
只有通过测试刚进入时已输入负数,您可以检测数:
这个'( - )'看起来不像有效的语法。 –