I wrote this piece of code, in which I ask the user to input numbers twice, and then it joins them together in a list, inside a list. It works…buts it’s in the wrong format.
Here’s what I did
list=[]
for i in range(2):
userinput = input("Enter some numbers: ")
x = userinput.split()
list.append(x)
print(list)
The output is this
Enter some numbers: 1 2
Enter some numbers: 3 4
[['1', '2'], ['3', '4']]
…but I need it to be formatted [[1, 2], [3, 4]]
I’m very new python, and I feel like Ive exhausted all my options, I couldnt find anything online that works (tried the join, replace etc.) , unless its impossible with my code, please help
>Solution :
Use x = [int(i) for i in userinput.split()]; you have to convert the input strings to integers.