-4

In part of my program, I need to download the numeric program and output it as a list. Get a number from the input and then export it as a list between each comma.

Sample:

Entrance:1230

Output:[1,2,3,0]

  • 3
    What is the code you are having trouble with? What trouble do you have with your code? Do you get an error message? What is the error message? Is the result you are getting not the result you are expecting? What result do you expect and why, what is the result you are getting and how do the two differ? Is the behavior you are observing not the desired behavior? What is the desired behavior and why, what is the observed behavior, and in what way do they differ? Please, provide a [mre]. – Jörg W Mittag Apr 07 '20 at 03:50
  • Does this answer your question? [Get a list of numbers as input from the user](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user) – Gino Mempin Apr 07 '20 at 04:15

2 Answers2

0

Assuming input is used for string input, you can use list() to cast a string to a list of characters.

user_number = input("Input a number: ")
number_list = list(user_number)
Nathansbud
  • 11
  • 5
0
a = 1234

print(list(map(int,list(str(a)))))

output:

[1, 2, 3, 4]

its a little messy so to break it down

a = 1234
a = str(a) # '1234'
a = list(a) # ['1', '2', '3', '4']
a = list(map(int, a)) # turns each element into an int
The Big Kahuna
  • 2,097
  • 1
  • 6
  • 19