-8
number = int(input())
numList = [int(digit) for digit in str(number)]
print(numList)

In this code when i enter the number 010 the output is being [1, 0] instead of [0, 1, 0]. please help Can i also get suggestion on how to add 0 to list if input number begins with 0

Aaditya
  • 1
  • 2

2 Answers2

2

Try this :

number = input()
numList = [int(digit) for digit in number]
print(numList)

Explanation:

Whenever you take a user input, it is considered as string. So you input 0110 will be saved in number variable as string "0110".

Now you can iterate over the string characters and convert them to integers in list comprehension.

Prashant Kumar
  • 2,057
  • 2
  • 9
  • 22
-2
numberList = []
number = input("Enter the number: ")
for xx in number:
    numberList.append(int(xx))


print("LİST: ",numberList)