Can anyone tell me. How to solve this question. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Can anyone tell me. How to solve this question.

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".

14th Mar 2021, 11:55 AM
Navraj Singh
Navraj Singh - avatar
21 Answers
+ 10
First of all in line 4 you have to check variable x so in place of input type x. Second, remove line 5 because you don't have to print stop according to question you have to print only sum. Here's the code, Hope you understood!! sum = 0 while True: x = input() if x == "stop": break else: sum += int(x) print(sum)
14th Mar 2021, 12:39 PM
Vinayak Pandey
Vinayak Pandey - avatar
+ 4
Please the community want to see your code before.Then we will try to help😉 Thanks for understanding
14th Mar 2021, 11:58 AM
!Derrickee
!Derrickee - avatar
+ 2
The question is in description
14th Mar 2021, 12:01 PM
Navraj Singh
Navraj Singh - avatar
+ 2
I mean show us your try
14th Mar 2021, 12:02 PM
!Derrickee
!Derrickee - avatar
+ 1
This code should work: total = 0 while (True): num = input("Enter a number: ") if (num == "stop"): break total += num print(num) :)
14th Mar 2021, 9:48 PM
Lewis Searle
Lewis Searle - avatar
+ 1
Navraj, in your code, the problem is that your code should not print "stop" when it is inputted. That is all of the problem.
15th Mar 2021, 6:15 PM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
Navraj Code has bug if input == "stop": Needs to be replaced it with following if x == "stop": DHANANJAY
16th Mar 2021, 4:44 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 1
sum = 0 while True: x = input() if x != 'stop': sum += int(x) else : break print(sum)
13th Dec 2021, 4:14 PM
Marcelo Goes de Freitas
Marcelo Goes de Freitas - avatar
0
Can you tell me what's wrong in this code?? sum = 0 while True: x = input() if input == "stop": print("stop") break else: sum +=int(x) print(sum)
14th Mar 2021, 12:06 PM
Navraj Singh
Navraj Singh - avatar
0
sum = 0 while True: x = input() #your code goes here if x=='stop': break else: sum=sum+int(x) print(sum)
2nd Jun 2021, 4:19 PM
Likhitha Ankinapalli
0
another one sum = 0 while True: x = input() #your code goes here if x != "stop": sum = sum + int(x) else: break print (sum)
1st Aug 2021, 2:35 PM
Marcosuru
Marcosuru - avatar
0
Here's my code: sum = 0 while True: x = input() if x != 'stop': sum += int(x) if x == 'stop': break print(sum)
12th Sep 2021, 1:20 AM
C'loni Bailey
0
Why my code does not work? sum = 0 while True: x = input() #your code goes here x += 1 if x == "stop": break else: sum += int(x) print(sum)
12th Sep 2021, 12:44 PM
Magdalena
0
Sorry but I do not understand a word you have written?
13th Sep 2021, 5:05 PM
Magdalena
0
Please, Am I tolerable or not ? DHANANJAY PATEL
13th Sep 2021, 9:50 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
0
Can anyone help me? I have asked you guys two days ago.. I am frustrated because can't move forward and honestly I have no idea what is wrong with my code and what I am doing wrong....
14th Sep 2021, 7:23 PM
Magdalena
0
Try this one and you'll get results sum=0 while True: x = input() #your code goes here if x != "stop": sum = sum + int(x) # print(sum) else: break print(sum)
18th Oct 2021, 7:31 PM
Ahmed Ali Ali Dino
Ahmed Ali Ali Dino - avatar
0
100% correct sum = 0 while True: x = input() #your code goes here if x == "stop": break sum = sum + int(x) print(sum)
10th Nov 2021, 2:20 PM
Chen qian
Chen qian - avatar
0
Type in the code that allows for entering a number and storing it in the variable a: >> a;
22nd Apr 2022, 10:31 AM
Utkarsh Rai
0
Fill in the blanks to create a loop that outputs all the numbers from 1 to 100 except the number 42
26th Dec 2022, 4:49 PM
Mahmoud Ayman
Mahmoud Ayman - avatar