I am solving a problem on http://hackerrank.com using Python 2
The compiler is giving an error
Traceback (most recent call last): File "/run-Lx3mHJ3G2jHRLRW9bjbX/solution.py", line 4, in t = raw_input() EOFError: EOF when reading a line
This is the code :
import sys
a = []
while 1:
t = raw_input()
if t=="":
break
else:
s = [i for i in t]
s.reverse()
a.append(s)
a.reverse()
for i in a:
for j in i:
sys.stdout.write(j)
sys.stdout.write('\n')
When I run it on my computer, it works fine.
Is it a problem I should report with the HackerRank interpreter or am I doing something wrong?
For sake of complete information, I already tried using "input()", "str(input())" and other possible variants.
HackerRank seems not to support the python idiom of repeating raw_input() until it gets an empty line. HackerRank apparently requires the submitted code to use the test description parameters in the header section (first line or two of input) to control the number of lines read.
Attempting to read past the last expected input line triggered a similar EOFError in my trials:
...
def main():
lines = []
line = raw_input()
while line:
lines.append(line)
line = raw_input() # line 232
...
resulted in
Status: EOFError thrown on line 232
Rewriting the input code to read just the expected number of lines was enough for the revised submission to pass. For example, for the 'Service Lane' warmup exercise in the Algorithms section:
...
first_line = raw_input()
freeway_length, testcase_count = parse_session_controls(first_line)
second_line = raw_input()
widths = parse_widths(second_line, freeway_length)
for _unused in range(testcase_count):
testcase_line = raw_input()
entrance_num, exit_num = parse_testcase(testcase_line, freeway_length)
print(measure_bottleneck(widths, entrance_num, exit_num))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With