Reputation: 4609
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?
Upvotes: -1
Views: 152
Reputation: 15944
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?
Upvotes: 2