title: hackerrank day 8 python
body: <p><strong>SPOILER</strong> This questions is about the Hackerrank Day 8 challenge, in case you want to try it yourself first.</p>
  
  <p>This is the question they give:</p>
  
  <blockquote>
    <p>Given <em>n</em> names and phone numbers, assemble a phone book that maps
    friends' names to their respective phone numbers. You will then be
    given an unknown number of names to query your phone book for. For
    each <em>name</em> queried, print the associated entry from your phone book
    on a new line in the form name=phoneNumber; if an entry for is not
    found, print Not found instead.</p>
    
    <p>Note: Your phone book should be a Dictionary/Map/HashMap data
    structure.</p>
    
    <p>The first line contains an integer, <em>n</em>, denoting the number of
    entries in the phone book. Each of the <em>n</em> subsequent lines describes
    an entry in the form of 2 space-separated values on a single line. The
    first value is a friend's name, and the second value is an 8-digit
    phone number.</p>
    
    <p>After the <em>n</em> lines of phone book entries, there are an unknown number
    of lines of queries. Each line (query) contains <em>name</em> a to look up,
    and you must continue reading lines until there is no more input.</p>
    
    <p>Note: Names consist of lowercase English alphabetic letters and are
    first names only.</p>
  </blockquote>
  
  <p>They go further then to give the input:</p>
  
  <pre><code>3
  sam 99912222
  tom 11122222
  harry 12299933
  sam
  edward
  harry
  </code></pre>
  
  <p>which expects the output:</p>
  
  <pre><code>sam=99912222
  Not found
  harry=12299933
  </code></pre>
  
  <p>I am having trouble with the unknown number of names to query. I tried using a try/except block to stop at an EOFError but I keep timing out on their test cases 1, 2 and 3. It works on two of the other test cases but not those and I assume it must be because I am stuck in a kind of infinite loop using my while True statement? This is what I wrote:</p>
  
  <pre><code>phonebook = {}
  entries = int(raw_input())
  
  for n in range(entries):
      name, num = raw_input().strip().split(' ')
      name, num = [str(name), int(num)]
      phonebook[name] = num
  
  while True:
      try:  
          search = str(raw_input())
  
          if search in phonebook.keys():
              output = ''.join('%s=%r' % (search, phonebook[search]))
              print output
          else:
              print "Not found"
      except EOFError:
          break
  </code></pre>
  
  <p>I am still fairly new to python so maybe I'm not using the try/except or break methods correctly? I would appreciate if anyone could tell me where I went wrong or what I can do to improve my code?</p>