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
Fair Use means a teacher can take the contents of a web activity page and repost it in your school's web site because it is for
guajiro [1.7K]

It's false because that teacher used someone's content without getting the consent of the owner which can also be referred as a unethical work.

6 0
4 years ago
What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in a
White raven [17]

Answer and Explanation:

The benefit of circuit switching is that it has a specialized circuit without exchanging (guaranteed performance). Packet-Converting uses either TDM or FMD. TDM has the added benefit of being able to use most of the (multiplexing) bandwidth.

  • It is the most recognizable method used to create a communication over network is circuit switching.
  • It can be used for regular phone conversations.
  • This enables people to share devices and circuits for conversation.
  • Through network utilization, every user has an exclusive connection to a circuit.
8 0
3 years ago
Snippet 1: check_file_permissions.c #include
vitfil [10]

Answer:

I don't know  you should figure that out good luck

Explanation:

good luck

3 0
3 years ago
If we assume the modern view of existential import, why is the following syllogism invalid? No computer is made of clay. All com
Papessa [141]

Answer:

<u>because the conclusion is not in agreement with the two premises.</u>

Explanation:

<em>Remember</em>, the term<u> syllogism</u> refers to the form of reasoning that draws its conclusion based on the stated premises. In other words, a conclusion is reached if it satisfies <em>all or part </em>of the premises.

In this case, the statement "No computer is made of clay" and  "All computers are electronic devices" should be inferred to mean, <em><u>No </u></em><em>electronic devices are made of clay" </em>not<em> </em><em>"Some electronic devices are not made of clay," </em>since the two premises neither suggest that electronic devices are made from clay.

5 0
3 years ago
What do you think of my profile picture
Gnom [1K]

ayo it's pretty sweet lma.o.

8 0
3 years ago
Read 2 more answers
Other questions:
  • The rmdir command (with no options) can only remove empty directories <br> a. True <br> b. False
    14·1 answer
  • A retail company assigns a $5000 store bonus if monthly sales are $100,000 or more. Additionally, if their sales exceed 125% or
    5·1 answer
  • More recent GPU families such as Fermi and Kepler have adopted CPU-style virtual memory architecture with a____________-bit virt
    8·1 answer
  • A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the clie
    8·1 answer
  • EX 3.8 Write code to declare and instantiate an object of the Random class (call the object reference variable rand). Then write
    6·1 answer
  • One of the most common encryption protocols in use today. It is an asymmetric protocol that enables the sharing of a secret key
    7·1 answer
  • Write an enhanced for loop that multiplies all elements in an int[] array named factors, accumulating the result in a variable n
    11·1 answer
  • _____ is rampant with bugs and shortcomings because most programmers do not know how or do not take the time to incorporate secu
    14·1 answer
  • You have been asked to replace a cracked screen on a laptop. The replacement screen was delivered today, but it did not include
    7·1 answer
  • Multiple Select Which of these are ways a hacker might learn someone's password? Select 3 options. o social engineering keylogge
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!