Jump to content


Photo

Ch 5 - Keyword Can't Be An Expression Error - P. 157

chapter 5 hash key keyword value

  • Please log in to reply
1 reply to this topic

#1 lefthandlauren

lefthandlauren

    New Member

  • Members
  • Pip
  • 2 posts

Posted 31 May 2015 - 03:37 PM

I'm using Python 3 on Mac Yosemite (10.10.3)

When I enter the code from page 157 and run the module, I get an error stating "keyword can't be an expression"

 

Here is my code: 

 

scores = {}
result_f = open("results.txt")
for line in result_f:
    (name, score) = line.split()
    scores[score] = name
result_f.close()
 
print("The top scores were: ")
for each_score in scores.keys():
    print('Surfer ' + scores[each_score] = ' scored ' + each_score)
 
 
It almost seems like it doesn't like using print in a for loop, but that should be possible. I can't find any other forum posts on this particular error. I've checked and re-checked all spaces, indents, etc. and can't find a single difference between my code and the book's. Thanks for any insight you can provide!


#2 lefthandlauren

lefthandlauren

    New Member

  • Members
  • Pip
  • 2 posts

Posted 02 June 2015 - 05:28 PM

I checked this about 100 times for typos before posting. Walked away, came back two days later...found my typo. So never mind, issue resolved.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users