Photo

I'm Stuck On Page 167.


  • Please log in to reply
2 replies to this topic

#1 Kim Tae IL

Kim Tae IL

    New Member

  • Members
  • Pip
  • 2 posts

Posted 12 August 2015 - 11:36 PM

Hi, I'm stuck on page 167. 

 

I can get the information when I type "101", but if I input another number rather than "101", it seems it didn't work. I don't know why... Any body can help me??

def find_details(id2find):
    surfers_f = open("surfing_data.txt") 
    for each_line in surfers_f: 
        s = {} 
        (s['id'], s['name'], s['country'], s['average'], s['board'], s['age']) = each_line.split(";") 
        if id2find == int(s['id']): 
            surfers_f.close()
            return(s)
        surfers_f.close()
        return({})
    
lookup_id = int(input("Enter the id of the surfer: "))
surfer = find_details(lookup_id)
if surfer:
    print("ID:         " + surfer['id'])
    print("Name:       " + surfer['name'])
    print("Country:    " + surfer['country'])
    print("Average:    " + surfer['average'])
    print("Board type: " + surfer['board'])
    print("Age:        " + surfer['age'])
else:
    print("Not found!!")
    



#2 Kim Tae IL

Kim Tae IL

    New Member

  • Members
  • Pip
  • 2 posts

Posted 13 August 2015 - 12:51 AM

Oops.. I have resolved the issue. I have just commented line 9, 10 and it works now!! 



#3 TheFuture

TheFuture

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 August 2015 - 08:19 AM

Oops.. I have resolved the issue. I have just commented line 9, 10 and it works now!! 

 

Hi kim, I think you should just take those lines out of the if condition and not commenting them.

Do you agree?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

"