When you give your program the sample input given in the problem, it should produce exactly the same output as the sample output given in the problem. Nothing else. No prompts, no error messages, no extra spaces or new lines.
Does your program do that?
If you go to ideone.com, create a python program, and request a sample, it gives the code below, which is an example solution to this problem. That should get you started on one way to read the input.
from sys import stdin
for line in stdin:
n = int(line)
if n == 42:
break
print(n)