0

Why am I getting no output?

sum = 0 x = int(input()) while True: sum+=x if x == "stop": break print(x)

23rd Aug 2021, 4:14 PM
James Murphy
James Murphy - avatar
6 Respuestas
+ 1
x is an integer, it will never equal "stop". Therefore the loop will run infinitely and nothing is printed
23rd Aug 2021, 4:18 PM
Lisa
Lisa - avatar
+ 1
I think you want to take multiple inputs, right? * put x = input() inside the loop * first check if x == stop (if so, break) * if not, you can do x = int(x) and add to sum
23rd Aug 2021, 4:52 PM
Lisa
Lisa - avatar
0
Thank you very much.
23rd Aug 2021, 4:20 PM
James Murphy
James Murphy - avatar
0
Sorry but now I have another problem. If I don't change the input to an integer, I can't add the numbers? Can I? I get an error for line 4.
23rd Aug 2021, 4:30 PM
James Murphy
James Murphy - avatar
23rd Aug 2021, 4:35 PM
Simon Sauter
Simon Sauter - avatar
0
Thanks very much, I'll give it another go.
23rd Aug 2021, 4:54 PM
James Murphy
James Murphy - avatar