Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program of Exercise P8.17 is not very user-friendly because it requires the user to know the exact spelling of the country name. As an

The program of Exercise P8.17 is not very user-friendly because it requires the user to know the exact spelling of the country name. As an enhancement, whenever a user enters a single letter, print all countries that start with that letter. Use a dictionary whose keys are letters and whose values are sets of country names.

Use the rawdata_2004.txt file, provided below, to load your dictionary.

Can you please solve this question by the following template in python?

# Read a database of per capita income by country and allow the user to # query it. # # Load the data into a dictionary. incomes = {} inf = open("rawdata_2004.txt", "r") for line in inf: parts = line.split("\t") # Remove the dollar sign and comma. parts[2] = parts[2].replace("$", "") parts[2] = parts[2].replace(",", "") # Add the country to the dictionary. incomes[parts[1].upper()] = float(parts[2]) # Read queries from the user and respond to them. country = input("Enter a country name (or type quit to quit): ").upper() while country != "QUIT" : if country in incomes : print("The per capita income is", incomes[country]) else : print("That wasn't a recognized country.") print() # Read the next country from the user. country = input("Enter a country name (or type quit to quit): ").upper()

Here the key is a country name and the value is income.

But I want the key is letter and value is all country's name starting with same letter by using same rawdata_2004.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Sales results over time.

Answered: 1 week ago

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago