NZEC Error in Python..

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 “\n”.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…

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

2 Likes

Thanks alot…:slight_smile:

In Python, the print statement automatically starts from a new line, so a better and simpler implementation of this could be like this… CodeChef: Practical coding for everyone