Question

PYTHON PROGRAM

by using functions & dictionary or set.

- must create a variable to hold a dictionary or sets

- must define a function that accepts dictionaries or sets as an argument

A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keysBelgium Ivory Coast Italy Senegal El Salvador Central African Republic Ecuador France Equatorial Guinea Ireland Euro CFA fran

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We append each country to the result whose currency is the one as required by the user.

 def reverseLookup(country_currency,currency): countries=[] for key in country_currency: if country_currency[key]==currency: countries.append(key) return countries def main(): currency=input("Please enter the currency for which countries are to be found: ") country_currency={ 'Cameroon': 'CFA franc', 'Greece': 'Euro', 'Chad': 'CFA franc', 'Austria': 'Euro', 'Niger': 'CFA franc', 'Estonia': 'Euro', 'Finland': 'Euro', 'Republic of the Congo': 'CFA franc', 'United States': 'USD', 'Gabon': 'CFA franc', 'Germany': 'Euro', 'Belgium': 'Euro', 'Ivory Coast': 'CFA franc', 'Italy': 'Euro', 'Senegal': 'CFA franc', 'El Salvador': 'USD', 'Central African Republic': 'CFA franc', 'Ecuador': 'USD', 'France': 'Euro', 'Equatorial Guinea': 'CFA franc', 'Ireland': 'Euro' } print("{} is ised in the following countries: ".format(currency)+','.join(reverseLookup(country_currency,currency))) main()

def reverseLookup (country_currency, currency): countries=[] for key in country_currency: if country currency[key)==currency:

Sample output,

Please enter the currency for which countries are to be found: USD USD is ised in the following countries: United States, El

Add a comment
Know the answer?
Add Answer to:
PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3 Dn Ent Write a python program to create a Dictionary named grade with the given...

    3 Dn Ent Write a python program to create a Dictionary named grade with the given items and do the below operations: i. 15 i. Create Dictionary with keys-{'Monday', 'Tuesday', 'Wednesday Thursday', 'Friday') ii. values-{1, 2, 3, 4, 5) ii. Now append another item with key-'Saturday') and value-(63 to the already created Dictionary and print it.

  • USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are...

    USING PYTHON! a) Programmatically (do not just write a definition!) create a dictionary whose keys are the integers 1 through 10 and whose respective values are the keys cubed (e.g. a key of 5 has a value of 125). b) Write a function that, given a user inputted string, outputs a dictionary where each letter is a key and each value is the letter’s position in the string. Note that you ​must handle cases where a word could contain the...

  • they are 2 pictures attached 4) Delete set of keys from Python Dictionary Given: sampleDict =...

    they are 2 pictures attached 4) Delete set of keys from Python Dictionary Given: sampleDict = { "name": "Kelly", "age":25, "salary" : 8000, "city": "New york" } keysToRemove = ["name", "salary"] Expected output: {'city': 'New york', 'age': 25} 1) Write a Python program to iterate over dictionaries using for loops d = {'X': 10, y: 20, 'z': 30) 2) Write a Python program to get the maximum and minimum value in a dictionary my_dict = {'X':500, 'y':5874, 'z': 568} Sample...

  • using python Write a function that takes a dictionary and a list of keys as 2...

    using python Write a function that takes a dictionary and a list of keys as 2 parameters. It removes the entries associated with the keys from the given dictionary Your function should not print or return anything. The given dictionary should be modified after the function is called Note: it means that you can't create another dictionary in your function. Since dictionaries are mutable, you can modify them directly def remove_keys (dict, key_list) "" "Remove the key, value pair from...

  • Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys()...

    Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is MyDict = { 1: 'One', 2: 'Two', 3: 'Three' } Then ( 2 in MyDict.keys() ) evaluates to True, indicating that 2 is a valid key for MyDict....

  • Please help with this exercise on Python program involving the use of dictionary. ### This exercise...

    Please help with this exercise on Python program involving the use of dictionary. ### This exercise involves building a non-trivial dictionary. ### The subject is books. ### The key for each book is its title ### The value associated with that key is a dictionary ### ### In that dictionary there will be Three keys: They are all strings, they are: ### ### "Pages", "Author", "Publisher" ### ### ### "Pages" is associated with one value - an int ### ###...

  • This is a python question. from urllib import request import json """ Complete this program that...

    This is a python question. from urllib import request import json """ Complete this program that calculates conversions between US dollars and other currencies. In your main function, start a loop. In the loop, ask the user what currency code they would like to convert to And, how many dollars they want to convert. If you scroll down, you can see an example response with the available 3-letter currency codes. Call the get_exchange_rates() function. This function returns a dictionary with...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

  • This is a python question. Start with this program, import json from urllib import request def...

    This is a python question. Start with this program, import json from urllib import request def main(): to_continue = 'Yes' while to_continue == 'yes' or to_continue == 'Yes': currency_code = input("Enter currency code: ").upper() dollars = int(input("Enter number of dollar you want to convert: ")) # calling the exchange_rates function data = get_exchange_rates() if currency_code in data["rates"].keys(): currency = data["rates"][currency_code] # printing the the currency value by multiplying the dollars amount. print("The value is:", str(currency * dollars)) else: print("Error: the...

  • please do a and b Lab Exercise 9 Assignment Overview This lab exercise provides practice with...

    please do a and b Lab Exercise 9 Assignment Overview This lab exercise provides practice with dictionaries of lists and sets in Python. A. Write a program using Dictionaries of lists Consider the file named "lab9a.ру" Given two files named exactly continents. txt and cities.txt (no error checking of the file name is needed) of continents, countries and cities. Write a program to read continents, countries and their cities, put them in a nested dictionary and print them (no duplicates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT