0
Where is my mistake?
I want to input numbers and add them, but if I write stop the program stops and prints the total. sum = 0 while True: x = input() #your code goes here if str(x)=='stop': print(stop) else: continue sum+=int(x) print(sum)
3 Respostas
+ 2
Your whole if block should be indented under the while loop. Why are you printing a variable 'stop' which doesn't exist? Use the break statement to break out of the loop. Remove the continue statement from the else block because if you skip the iteration, when are you gonna add the numbers?
sum = 0
while True:
x = input()
#your code goes here
if x == 'stop':
break
else:
sum += int(x)
print(sum)
+ 1
Not sure why would you use continue ,
your if else are outside while loop and,
continue works inside a loop only.
Following should be the correct code,
sum = 0
while True:
x = input()
#your code goes here
if str(x)=='stop':
print("stop")
break
else:
sum+=int(x)
print(sum)
0
thank you