0

Stuck on door the math

Trying to figure out how to loop through user input, add it all up, and then also break when the user says “stop” I tried a single variable and got a type error (which is expected). I tried a second variable and no longer get the error but instead the output doesn’t add up correctly. sum = 0 while True: x = int(input()) y = input() sum += x print(sum) if y == "stop": break Any advice?

8th Sep 2021, 10:06 AM
John Corbin
5 Answers
+ 5
This question has been common lately, so please refer to the attached code. Substitute "stop" for "exit" https://code.sololearn.com/cBrr1eG5DV2t/?ref=app
8th Sep 2021, 10:18 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Ahhh that makes sense. In the challenge they provide the while loop and tell you to drop your code below it. Didnt occur to me to change the loop. Thanks!
8th Sep 2021, 10:20 AM
John Corbin
+ 1
I haven't seen the challenge. If it is specific to using break, then I could alter the code to show how to use the break function. Would you like to try yourself first?
8th Sep 2021, 10:22 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Yeah I’ll give it a go.
8th Sep 2021, 10:23 AM
John Corbin
+ 1
John Corbin Good choice buddy! Let us know how you go
8th Sep 2021, 10:24 AM
Rik Wittkopp
Rik Wittkopp - avatar