NZEC Error in Python..

nzec
nzecerror
python

#1

def main():
numbers=[]
count=0
while True:
num=raw_input("");
if not num:
break
elif num==“42”:
count=count+1
elif int(num)>0 and int(num)<100 and count==0:
numbers.append(num)
print "
".join(numbers)
return
main()
This solution is giving nzec error…and i have tried many solutions to this problem all with nzec error plzz help…


#2

Here are a few things about this code:-

  1. your code should break from loop when you encounter 42.it keeps taking input till it reaches end of file

2)the numbers are integers if 1 or 2 digits. so negative numbers like -1 , -24 should also be accepted.

3)there is no need to store numbers in a list. you can output them immediately after taking input

Here are 2 accepted versions of this code :code 1 and code 2


#3

Thanks alot…:slight_smile:


#4

In Python, the print statement automatically starts from a new line, so a better and simpler implementation of this could be like this… https://www.codechef.com/viewsolution/14287171