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
  • PYTHON Hello can someone create the following functions? I'm not sure how to start on them....

    PYTHON Hello can someone create the following functions? I'm not sure how to start on them. makeDictionary Define a function named makeDictionary with two parameters. The first argument passed the function must be a list of strings to be used as keys, while the second is a list of the same length containing values (of some type). This function must return a dictionary consisting of the keys paired with the corresponding values. For example, makeDictionary(['apno','value'],['REP-12','450']) must return this dictionary: {'apno':...

  • For Python 3 MPLS please 1. Given a variable, unproved_conjectures, that is associated with a dictionary...

    For Python 3 MPLS please 1. Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of mathematical conjectures to the years when the conjectures were made, write a statement that deletes the entry for "Fermat's Last Theorem". 2. Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of the new dictionary and the values of d become the keys...

  • 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 ### ###...

  • IN PYTHON You are building a program for a Point of Sale (POS) machine for a...

    IN PYTHON You are building a program for a Point of Sale (POS) machine for a fruit store. The inventory and price list are stored in a file (i.e. items.txt) with an example as follows: banana 3 1.25 apple 6 1.75 orange 32 0.5 pear 55 2.5 For illustration, the first line implies that "There are 3 bananas in the inventory and the price of a banana is $1.25" You have to write four functions: 1. The first function readstockprice...

  • 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...

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