I'm trying to write a code where the program keeps getting the user input in integers and adds it to an empty array. As soon as the user enters "42", the loop stops and prints all the collected values so far.
Ex:
Input:
1
2
3
78
96
42
Output:
1 2 3 78 96
Here is my code (which isn't working as expected):
num = []
while True:
in_num = input("Enter number")
if in_num == 42:
for i in num:
print (i)
break
else:
num.append(in_num)