+ 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".
21 Respostas
+ 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)
+ 4
Please the community want to see your code before.Then we will try to helpš
Thanks for understanding
+ 2
The question is in description
+ 2
I mean show us your try
+ 1
This code should work:
total = 0
while (True):
num = input("Enter a number: ")
if (num == "stop"):
break
total += num
print(num)
:)
+ 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.
+ 1
Navraj
Code has bug
if input == "stop":
Needs to be replaced it with following
if x == "stop":
DHANANJAY
+ 1
sum = 0
while True:
x = input()
if x != 'stop':
sum += int(x)
else :
break
print(sum)
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)
0
sum = 0
while True:
x = input()
#your code goes here
if x=='stop':
break
else:
sum=sum+int(x)
print(sum)
0
another one
sum = 0
while True:
x = input()
#your code goes here
if x != "stop":
sum = sum + int(x)
else:
break
print (sum)
0
Here's my code:
sum = 0
while True:
x = input()
if x != 'stop':
sum += int(x)
if x == 'stop':
break
print(sum)
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)
0
Sorry but I do not understand a word you have written?
0
Please, Am I tolerable or not ?
DHANANJAY PATEL
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....
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)
0
100% correct
sum = 0
while True:
x = input()
#your code goes here
if x == "stop":
break
sum = sum + int(x)
print(sum)
0
Type in the code that allows for entering a number
and storing it in the variable a:
>> a;
0
Fill in the blanks to create a loop that outputs all the numbers from 1 to 100 except the number 42