Life of universe , and Everything , I don't know where i am going wrong

lis = []

userinput = int(input("Enter elements that are not 42: "))

while(userinput != 42):
lis.append(userinput)
userinput = int(input())

for value in lis:
print(lis)

why does this gives an NZEC error.

Well, you should really look at how competitive programming online judge works.
Why are you using this:
userinput = int(input("Enter elements that are not 42: "))
In the problem, it is not said you need to print Enter the elements that are not 42 on STDOUT.

Moreover, why are you creating a list of numbers? If you carefully read the problem statement, it says that whatever integer value you read from the STDIN should go to STDOUT until the read integer == 42.
In the case of 42 you program should terminate.

Do remember that in python when you print a list, it is printed in the format [a, b, c, d, ...], which is not the required output as per the problem statement.

Use the following code-structure to solve the problem:

n = int(input().strip())
while(n != 42):
    print(n)
    n = int(input().strip())

Refer to the following video to know about competitive programming: https://www.youtube.com/watch?v=xAeiXy8-9Y8&t=499s

1 Like

@purplemushroom your code will not be accepted in this way because it has to be answered in specified format .
my code written in C is below .

#include <stdio.h>
int main(void)
{
while(1)
{
int n;
scanf("%d",&n);
if(n==42)
return 0;
else
printf("%d\n",n);
}
}

1 Like

In the question it is said that you are needed to take input from STDIN and print output to STDOUT where input is given one number in each line and output is expected to be printed one number in each line. While learning in college , to make the program understandable and user friendly during run time we print some text like enter a number , etc. but in competitive coding we are supposed to print just what is asked in the format they asked because our code would be tested by an online judge. so while printing the output use a for loop to print one element at a time in a new line and remove the text
("Enter elements that are not 42: ")
and your code would be good to go!

@purplemushroom purplemushroom , you are printing the entire list for len(list) times , (see line 7 of your code), instead of that you should print values that are stored in list , example you can write
for value in lis:
print(value)
Hope , this will help you :))-