+ 1
Hi can anyone help me with this test task
The given code uses an infinite loop to continuously take input from the user. During each iteration, user input is added to the list of items. Change the code to end the loop when the user enters 0. Output the resulting list after the while loop ends. Input example 1 two 3 0 Output example [1, 2, 3] I know how to make the infinite loop , and how make the input, the thing is that i don't know how to put them together to work, i know how to make a list but as well as the loop and the input (or intput) i don't know how to make a way to those things work all together. If anyone can help me I'll appreciate it
13 Answers
+ 2
Check this code,
a=[]
while True:
num=input()
if num!="0":
a.append(num)
else:
break
print(a)
+ 1
Show your attempt
0
It tells me (break is outside the loop
0
anthony silver it is very well inside loop and works fine for me.
0
Ok let me try again
0
I do it again and keep s telling me that break is outside the loop
0
The attempt that I try was the example that Abhay give me, if you read my cuestion, I said that i don't know how to make a way that work for the test task that i put as well in the description of my question. I need to make i way that infinite loop, an input ( or int input) an a list work all together as I said I the description
0
https://code.sololearn.com/cuaiVF4B4QS8/?ref=app
try some variation of this in your code. it should work for whatever you are trying to do with it
0
Thanks, the problem that I'm having now is that i don't know how to break the loop
0
Sorry I just understood what you mean! the code I first posted does not work for this case. I just replaced the code with 3 versions that do work. just uncomment the one you want to use and run it.
https://code.sololearn.com/cuaiVF4B4QS8/?ref=app
is that what you wanted to be able to do?
0
Yes that's something a little like what i need , thanks for your help
0
thanks for being patient with my bad answers!
0
Don't worry, all of this it's about patients and help each other, again thanks for your help Jesus Crist bless you