+ 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

3rd Mar 2021, 9:52 PM
Alan Restrepo
Alan Restrepo - avatar
13 Respuestas
+ 2
Check this code, a=[] while True: num=input() if num!="0": a.append(num) else: break print(a)
3rd Mar 2021, 10:07 PM
Abhay
Abhay - avatar
+ 1
Show your attempt
4th Mar 2021, 3:07 AM
Atul [Inactive]
0
It tells me (break is outside the loop
3rd Mar 2021, 10:22 PM
Alan Restrepo
Alan Restrepo - avatar
0
anthony silver it is very well inside loop and works fine for me.
3rd Mar 2021, 10:25 PM
Abhay
Abhay - avatar
0
Ok let me try again
3rd Mar 2021, 10:25 PM
Alan Restrepo
Alan Restrepo - avatar
0
I do it again and keep s telling me that break is outside the loop
3rd Mar 2021, 11:20 PM
Alan Restrepo
Alan Restrepo - avatar
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
4th Mar 2021, 3:26 AM
Alan Restrepo
Alan Restrepo - avatar
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
4th Mar 2021, 9:11 PM
Ethan
Ethan - avatar
0
Thanks, the problem that I'm having now is that i don't know how to break the loop
4th Mar 2021, 9:18 PM
Alan Restrepo
Alan Restrepo - avatar
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?
4th Mar 2021, 9:20 PM
Ethan
Ethan - avatar
0
Yes that's something a little like what i need , thanks for your help
4th Mar 2021, 11:00 PM
Alan Restrepo
Alan Restrepo - avatar
0
thanks for being patient with my bad answers!
4th Mar 2021, 11:04 PM
Ethan
Ethan - avatar
0
Don't worry, all of this it's about patients and help each other, again thanks for your help Jesus Crist bless you
4th Mar 2021, 11:17 PM
Alan Restrepo
Alan Restrepo - avatar