You are not logged in. Please login at www.codechef.com to post your questions!

×

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..

asked 27 Aug '13, 22:52

nimishsinghal's gravatar image

2★nimishsinghal
1247
accept rate: 0%


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

link

answered 27 Aug '13, 23:51

kcahdog's gravatar image

3★kcahdog
10.0k2854129
accept rate: 14%

Thanks alot..:)

link

answered 04 Oct '13, 19:56

nimishsinghal's gravatar image

2★nimishsinghal
1247
accept rate: 0%

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

link

answered 29 Aug '17, 00:46

rishik123's gravatar image

4★rishik123
404
accept rate: 14%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×518
×422
×125

question asked: 27 Aug '13, 22:52

question was seen: 6,709 times

last updated: 29 Aug '17, 00:46