How can i adding the user input? | Sololearn: Learn to code for FREE!
- 1

How can i adding the user input?

You’re making a calculator that should add multiple numbers taken from input and output the result. The number of inputs is variable and should stop when the user enters "stop". Sample Input 4 32 6 stop Sample Output 42 Use an infinite loop to take user input and break it, if the input equals to "stop".

21st Mar 2021, 12:03 AM
Endry Saputra
4 Respostas
+ 2
I did it bro sum = 0 while True: x = input() #your code goes here if x == 'stop': break sum += int(x) print (sum)
21st Mar 2021, 12:36 AM
Endry Saputra
0
can you post your attempt here please?
21st Mar 2021, 12:27 AM
Slick
Slick - avatar
0
code works perfectly! input should be as so: *hit run 1 2 3 4 stop *hit submit 10 # output sololearn handles input weird. Each value needs to be placed on a seperate line all at the same time when entering input. *even if input is needed much later in program it must be included here
21st Mar 2021, 12:41 AM
Slick
Slick - avatar
0
sum = 0 while True: x = input() if x == 'stop': break sum += int(x) print (sum)
23rd Sep 2021, 9:27 AM
Priyanka.c