+ 1

List. Help with list

Hi! I've been programming for a month and I have a question. When I do this: nums = list([(input())]) print (nums) the output Is not a list of numbers, but a string. Something like "3,4,5,6" if the input was 3,4,5,6. Question: Can I make a list of numbers [3,4,5] with the help of "input"??? I know that you can do this : list [] and every time you enter the desired data, I need it with " input" https://code.sololearn.com/cCKWp9uIreV8/?ref=app

30th Dec 2018, 10:19 AM
Sara H
Sara H - avatar
3 Réponses
+ 4
You can also do it this way: nums = [int(x) for x in input().split(',')] print(nums)
30th Dec 2018, 10:46 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
this is simple. x=input() #let x=1234 print(list(x)) #output=[1,2,3,4] If input in , Then try this. x=input() #let x=1,2,3,4 print(x.split(',')) output=[1,2,3,4] But remember in this list numbers is a string not an integer for that you can use int() function for it.
30th Dec 2018, 4:38 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
thank you very much
30th Dec 2018, 10:35 AM
Sara H
Sara H - avatar