my program doesn't work SOLVED | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

my program doesn't work SOLVED

hi everybody, I was doing some exercises when I found this one: Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list with those numbers. Output : List : ['3', ' 5', ' 7', ' 23'] so I wrote: list=[] i=0 while i<=3: list.append(input("type number")) i=i+1 print(list) but it doesn't work :/ Can you help me undersatnd why?

15th Nov 2020, 11:17 PM
Veronica
4 Answers
+ 2
Put print(list) out of the loop.
15th Nov 2020, 11:21 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 4
It sounds more like the expected input should be all numbers input separated by a comma at once, not inputting each number individually. I.E. Input: 1,2,3,4,5 Output: ['1', '2', '3', '4', '5'] In which case; print(input().split(','))
15th Nov 2020, 11:52 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
This would work if you run it from the terminal on your computer, but not sololearn which will only accept input once.
16th Nov 2020, 12:32 AM
Logomonic Learning
Logomonic Learning - avatar
+ 1
thank you very much everybody. IT WORKS!!!!!!!!
16th Nov 2020, 11:10 AM
Veronica