You are first assigning an empty list to x:
x = []
And then you assign a single int (twice):
for i in range (2):
x = int(input("enter a number: "))
1: x = []
2: x = first user input
3: x = second user input
What you want to do is append the user input to the list in x.
Either like this:
x.append(int(input("enter a number: ")))
Or like this:
x += [int(input("enter a number: "))]
The []
in the second example are required to add (+
) lists together as you can not add a list and a value but you can add two lists in terms of appending one to the other.
You could also use list comprehension:
x = [int(input("enter a number: ")) for i in range(2)]
solved (“print”), (“int” not subscritble), variables and list’s syntax in this code