 Do the math Practice | Sololearn: Learn to code for FREE!

+1

# Do the math Practice

sum = 0 while True: x = input() #your code goes here if input == "stop": print ("stop") else: sum += int(input()) print (sum) break I think I missed the mark? Anyway we are required to calculate the sum of user input and break it, if the user inputs (“stop”). Will keep practicing, as before I was just getting Errors, then I managed to get it to just output “stop”. Now I managed to output “2” so I think I should hopefully manage. However just in case I’m not on the right track.

+4

Oh, yes, you are right. My bad. Anyway, I get error sometimes, because I have indented block message. So the code is good, but place of a code in a line is wrong. But this code should work just fine: sum = 0 while True: x = input() if x == 'stop': break sum += int(x) print(sum)

+2

ANSWER SPOILER: You are so close. Put a break after print(“stop”). You don’t need the break at the end of the code. Then remove indents from your final print. Otherwise, you’ll get a list. sum = 0 while True: x = input() #your code goes here if x == "stop": break sum +=int(x) print(sum)

+2

@Luiza Haas, your code works good on 'Code PlayGround'. It works the same as 'else:' between break and sum += int(x). The problem is that it doesn't work on the problem "shell". Got this error: Traceback (most recent call last): File "/usercode/file0.py", line 7, in <module> sum += int(x) TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int' It's kinda crazy o_o PS: Your code did work! The error above was a tiny mistake on my behalf! Thanks alot!!! PSS:Oh and don't writte x == 'Stop' but 'stop'

+1

So you're supposed to accept values and add them up until the user enters 'stop', right? If so, then you must break the loop when the user enters 'stop'. So I think the break should be in the if clause and not in the else clause. Correct me if I'm wrong

+1

I have the same problem... If I do the code un 'code playground' eveything works fine but when I do the same code on the problem panel, I get that message. It's a little frustating :/

+1

For anyone looking, this worked for me. moving the print sum into the loop was what did it. sum = 0 while True: x = input() if x == ("stop"): print (sum) break else: sum += int(x)

+1

the correct code is the following: sum = 0 while True: x =input() if x == "stop": break else: sum += int(x) print(sum)

0

Trace back (most recent call last): File “/ usercode/ file0.py”, line 7 in <module> sum += int(x) ValueError: invalid literal for int() with base 10: ‘stop’ thanks for the assist though,... ill keep working on it

0

Arthur, shouldn't you just use "stop" instead 'stop' ?

0

It does the same work if it's quote or double-quote.

0