Answer:
Modify your program by replacing
for x in country:
country_gold.append(gold[x])
country_gold.append("Did not get gold")
with
for x in country:
try:
country_gold.append(gold[x])
except:
country_gold.append("Did not get gold")
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
try:
country_gold.append(gold[x]) ->This appends the country name to the country_gold list
Otherwise, the statement in the except clause is executed
except:
country_gold.append("Did not get gold") -> This appends "Did not get gold" to the country_gold list
To confirm what you've done, you may add the following line of code at the end of the program: print(country_gold)