1 / 4
Dec 2019

My code for TEST gives a runtime error NZEC meanwhile it runs perfectly well on my Python IDE. The code accepts inputs and puts them into an array until the user presses the Enter key and the code prints out the numbers till 42 is reached.

arr=[]
while True:
digit=input(“Enter number: “)
if digit==””:
break
if int(digit)<100:
arr.append(int(digit))
print(arr)
else:
print(“Number must be two digits or less”)
continue
for i in arr:
if i==42:
break
else:
print(i)

  • created

    Dec '19
  • last reply

    Dec '19
  • 3

    replies

  • 1.3k

    views

  • 2

    users

  • 2

    likes

  • 1

    link

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.com14, 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)

Thank you very much for the help. Does it mean I am to use stdin instead of the input() function in competitive programming?

Some of my AC Python solutions do use the input function, but do not pass anything for the prompt argument.