I was solving a problem on HackerRank when I encountered the following problem in my code. I tested it out on my Python (2.7.10) IDLE , and it was working fine. But it showed the following error on HackerRank:
Traceback (most recent call last):
File "solution.py", line 13, in <module>
input_2=input()
EOFError: EOF when reading a line
I entered the following code:
import sys
input_2=""
n=int(input())
m=0
l=0
array=[]
main_array=[]
for i in range (0,n):
inp=input()
array=(inp.split(" "))
main_array+=array
for no in range(0,100000,1):
input_2=input()
for m in range(0,len(main_array),2):
l=0
if input_2==main_array[m]:
l+=1
print (main_array[m]+"="+main_array[m+1])
if l==0:
print ("Not found")
I don't know why this error turned up in the HackerRank Engine. Thanks
I encountered similar EOF issues when I coded in HackerRank. Actually, there are 2 issues:
input()
in Python3 andraw_input()
in Python2.input()
. However, the difficulty is that you don't know how many inputs you will have. In this case, you will have to usesys.stdin.readlines()
to convert them into a list, and then use a for-each loop.The following codes are from "Editorial" of https://www.hackerrank.com/challenges/30-dictionaries-and-maps/
I don't know what are you exactly trying to achieve through your code, but you are getting an error due to the line
inp=input()
, which tries to take a string as input, whereas it's designed to take anint
,float
, orstring entered with quotes
inpython 2.7
. Useraw_input()
instead to take the complete line as string input, and then split it withspace
as delimiter.I followed the link you provided, and I see that the given question needs to be solved using
dictionaries
. Hence, instead of appending thename
andnumber
, just store it indictionary
as akey-value
pair and for each query, just check whether the key exists in the dictionary or not. If not, printNot found
, else print the key and its corresponding value. Here is the code for reference :Hope this helps !