-1

I've the following python 2.7.3 code which I am submitting to codechef online programming contest:

case = input() 
for i in xrange(0, case):
    try:
        l = [elem for elem in raw_input().split()]
        res = int(l[0][::-1]) + int(l[1][::-1])
        print int(str(res)[::-1])
    except:
        break

This works on my computer, even when I use input redirection and use a in.txt file for input, still it works.

But the problem is when i submit it for evaluation, I get an exception and that exception gets removed when I use raw_input for getting the value of case

case = int(raw_input())

My in.txt file is as follows:

1
23 45

My problem is that its working on my computer perfectly, what is it that the online contest site feeding at the 1st line that an exception is being raised, and further it gets rectified when I use raw_input.

Shouldn't input() also work when my 1st line is always an integer?

2
  • The site doesn't tell me that, though it gets rectified on using raw_input. Commented May 28, 2012 at 19:29
  • What version of Python is the contest using? Commented May 28, 2012 at 19:32

1 Answer 1

2

Most likely, the site that you're submitting the code to disables the input command. This is sometimes done as part of "sandboxing", to prevent you from running arbitrary code on their machine. E.g., they wouldn't want to let you run a script that deletes all files on their disk.

The input command is more-or-less equivalent to running eval(raw_input()), and eval can be used to do just about anything.

You say you get an exception. Exactly what kind of exception, and what is the exception message?

Sign up to request clarification or add additional context in comments.

3 Comments

I am getting a NZEC runtime error and on their site it is explained as follows: Why do I get an NZEC? NZEC stands for Non Zero Exit Code. For C users, this will be generated if your main method does not have a return 0; statement. Other languages like Java/C++ could generate this error if they throw an exception.
So you see it says for other languages it is due to an exception, but it doesn't tell the exception message.
Try submitting one of the following as your complete program, and see if you get a similar error: eval("1+2") or just input(); alternatively, if it lets you see the console output (stout), then wrap everything in a try...except that catches and prints the exception.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.