I am at the moment of understanding how lists and while loops work in Python. Unfortunately, I am a bit confused with my code.
main_list = []
list_1 = [1, 2]
list_2 = [3, 4]
i = 0
n = 2
while i != n:
number = int(input("Insert a number: "))
list_1.append(number)
main_list.append(list_1)
main_list.append(list_2)
i += 1
print(main_list)
Why am I getting an output of this,
>> Insert a number: 2
>> Insert a number: 3
>> [[1, 2, 2, 3], [3, 4], [1, 2, 2, 3], [3, 4]]
instead of this?
>> Insert a number: 2
>> Insert a number: 3
>> [[1, 2, 2], [3, 4], [1, 2, 2, 3], [3, 4]]
I would appreciate if anyone can explain it to me, thank you.