Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6041323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:38:42+00:00 2026-05-23T06:38:42+00:00

Please be gentle, I’m very new to programming and only own one book which

  • 0

Please be gentle, I’m very new to programming and only own one book which is giving me some terrible directions (Head First Programming). Here is the code I have in the Python IDLE:

scores = {}

scores[8.45] = 'Zach'
scores[9.12] = 'Juan'
scores[8.31] = 'Aaron'
scores[8.05] = 'Aideen'
scores[8.65] = 'Johnny'
scores[7.81] = 'Stacey'

for key in scores.keys():
    print(scores[key] + ' had a score of ' + scores[???])

The program is meant to print a list containing both the names of the contestants and their corresponding scores but I dont know what I am doing wrong or right at this point :/

EDIT: Thank you guys. With your help i edited the code to working order, if you’re interested here it is:

scores = {}

scores['Zach'] = 8.45

scores['Juan'] = 9.12

scores['Aaron'] = 8.31

scores['Aideen'] = 8.05

scores['Johnny'] = 8.65

scores['Stacey'] = 7.81

for key in scores.keys():    
    print(str(key), ' had a score of ' , scores[key])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:38:43+00:00Added an answer on May 23, 2026 at 6:38 am

    You can use the {...}.items() iterator as follows:

    for score,name in scores.items():
        print('{name} had a score of {score}'.format(**locals()))
    

    However, your dictionary is in the wrong order. For example, what if Zach and Juan had the same score of 9.10? Then, writing scores[9.10]='Zach' scores[9.10]='Juan' would overwrite Zach! The keys should be the names.

    You can write it like this:

    scores['Zach'] = 8.45
    scores['Juan'] = 8.45
    ...
    

    For the record, here’s how I’d do it from scratch:

    def parseScores(string):
        scores = {}
        for line in string.splitlines():
            if line.strip():
                name,score = line.strip().split()
                scores[name] = float(score)
        return scores
    
    data = """
        Zach 8.45
        Juan 9.12
        Aaron 2.2
        Aideen 2.2
        Johnny 2.2
        Stacey 7.81
    """
    
    scores = parseScores(data)
    for name,score in scores.items():
        print('{name} had a score of {score}'.format(**locals()))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please be gentle, as I'm still new to web programming and -very- new to
I am very new to iPhone development, so please be gentle with me. I
Totally new to Drupal so be gentle please! Let's say I have a number
I'm relatively new with hibernate so please be gentle. I'm having an issue with
Brand spanking new to Regex in Rails so please be gentle... I found the
I'm kinda new to this topic so please be gentle ;) I'm attempting to
OK, first off, I am new at this so be gentle (please). I am
Please suggest some good resources to start writing Java Web services.
Please explain to me why the very last echo statement is blank? I expect
This is my first question so please be gentle. :-) I know AspectJ can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.