1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vivado [14]
4 years ago
8

The code below takes the list of country, country, and searches to see if it is in the dictionary gold which shows some countrie

s who won gold during the Olympics. However, this code currently does not work. Correctly add try/except clause in the code so that it will correctly populate the list, country_gold, with either the number of golds won or the string "Did not get gold".
1
​2 gold = {"US":46, "Fiji":1, "Great Britain":27, "Cuba":5, "Thailand":2, "China":26, "France":10}
3 country = ["Fiji", "Chile", "Mexico", "France", "Norway", "US"]
4 country_gold = []
5
​6 for x in country:
7 country_gold.append(gold[x])
8 country_gold.append("Did not get gold")
Computers and Technology
1 answer:
Lisa [10]4 years ago
4 0

Answer:

Modify your program by replacing

<em>for x in country: </em>

<em>        country_gold.append(gold[x]) </em>

<em>        country_gold.append("Did not get gold")</em>

with

<em>for x in country: </em>

<em>        try: </em>

<em>                country_gold.append(gold[x]) </em>

<em>        except: </em>

<em>                country_gold.append("Did not get gold") </em>

<em />

Explanation:

The addition of try/except clause in the program is to let the program manage error;

In this case, the program checks for a country in the list country; This is implemented using the following line

for x in country:

If the country exists, the statement in the try block is executed

<em> try: </em>

<em>  country_gold.append(gold[x])  -></em><em>This appends the country name to the country_gold list</em>

Otherwise, the statement in the except clause is executed

<em> except: </em>

<em>  country_gold.append("Did not get gold")  -> </em><em>This appends "Did not get gold" to the country_gold list</em>

<em />

<em>To confirm what you've done, you may add the following line of code at the end of the program: </em>print(country_gold)

You might be interested in
Which PlayStation was the first to allow connection between it and computer network
Bezzdna [24]

If you're talking about connecting to the internet internet, it would be the PS2. You could buy an adapter for an ethernet cable to allow for online play.

4 0
4 years ago
True and false 1. Trace topology is also referred to as tree bus topology. ​
algol13

Answer:

Trace topology is also referred to as tree bus topology.

Explanation:

6 0
2 years ago
What is the smallest negative integer that can be represented in two's complement system in which each value is represented by e
olga nikolaevna [1]

Answer:  Two's complement is a mathematical operation on binary numbers, and is an example of a radix complement. It is used in computing as a method of signed number representation.

8 0
3 years ago
Why is it a mistake to put e-mail address of people who don't know each other in the "to:" field
Ber [7]
They would probably think that you sent the email to the wrong person and then delete it.
7 0
4 years ago
Read 2 more answers
What is sent back after you sent FAFSA
MrRa [10]
FAFSA will send you back a SAR (Student Aid Report). They will send you an email giving you instructions on what to do what not to do. Which will be sent to you in a week. Then they will decide if the application is Approved or complete and rejected.
8 0
4 years ago
Other questions:
  • Consider a multiprocessor CPU scheduling policy. There are 2 options: 1) a singlecommon ready queue of jobs; when a CPU becomes
    8·1 answer
  • 2
    9·2 answers
  • Having one password for all accounts is an easy way to remember passwords, but it will expose you to what risk?
    15·1 answer
  • Which storyboard component is a pictorial summary of how web pages in a website will connect with one another?
    12·1 answer
  • Encryption is the key to keeping your personal information secure online.<br><br> True<br><br> False
    11·1 answer
  • How are people using lying today? What are the types of lying? Describe each type.
    7·1 answer
  • A ___________ variable is used to add up a set of values. fill in the blank
    8·1 answer
  • Test if the word mold is stored in the variable word. Computer science.
    9·1 answer
  • HELP WILL GIVE BRAINLIEST !!!!!
    6·1 answer
  • write a recursive function that accepts an integer argument, n. the function should display n lines of asterisks on the screen,
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!