Question

In: Computer Science

*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names...

*Python*

1.1) Create an empty dictionary called 'addresses'.

The dictionary you just created will map names to addresses. A person's name (stored as a string) will be the KEY and that person's address (stored as a string) will be the VALUE.

1.2) Insert into the dictionary 'addresses' the names and addresses of two (possibly imaginary) friends of yours.

1.3) Create a second empty dictionary called 'ages'.

The dictionary you just created will map names to ages. A person's name (stored as a string) will be the KEY and that person's age (stored as an integer) will be the VALUE.

1.4) Insert into the dictionary 'ages' the names and ages of the same two (possibly imaginary) friends of yours. (Note: these two friends must be the same two friends that you inserted into the dictionary 'addresses' earlier.)

1.5) Using a for loop, print out, for each friend, the information available about them in a single sentence. For example, if your dictionaries contained the age and address of your friends 'Mary Jones' and 'Miguel Hernandez', then your code would output:

Mary Jones is 20 years old and lives at 28 Union St, Brooklyn, NY.
Miguel Hernandez is 21 years old and lives at 394 Fifth Avenue, New York, NY.

Solutions

Expert Solution

I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).

Images of the Code:


Note: If the below code is missing indentation please refer code Images

Typed Code:

#Empty dictionary
addresses = {}
#inserting names and addresses
addresses['Mary Jones'] = '28 Union St, Brooklyn, NY'
addresses['Miguel Hernandez'] = '394 Fifth Avenue, New York, NY'
#Second empty dictionary
ages = {}
#inserting names and ages
ages['Mary Jones'] = 20
ages['Miguel Hernandez'] = 21
#for loop will iterate for 2 times because 2 items in addresses dictionary
for key,value in addresses.items():
#printing name and ages[name] and value
print("{} is {} years old and lives at {}.".format(key,ages[key],value))
//code ended here

Output:


If You Have Any Doubts. Please Ask Using Comments.

Have A Great Day!


Related Solutions

Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
Instructions: Create an empty dictionary: zip_dict = {} Loop through all the zip_codes in df_zip Create...
Instructions: Create an empty dictionary: zip_dict = {} Loop through all the zip_codes in df_zip Create a dictionary key for the first 3 digits of a zip_code in zip_dict Continually add population counts to the key that contains the same first 3 digits of the zip code To extract the population you will find this code useful: population = list(df_zip.loc[df_zip['zip'] == zip_code]['population']) To extract the first 3 digits of a zip_code you will find this code useful: int(str(zip_code)[:3])
1.Suppose a dictionary Groceries maps items to quantities.     Write a python to print the names...
1.Suppose a dictionary Groceries maps items to quantities.     Write a python to print the names of the grocery items whose quantity exceeds 400.     For example, if groceries = {‘cake mixes’: 430, ‘cheese’:312, ‘Orange’:525, ‘candy bars’: 217}         The output will be                                 Cake mixes                                 Orange 2. which Python string method would be the best choice to print the number of time “the” occurs in a sentence entered by the user? Provide a one word answer. Just...
Using python. 1. How to create a dictionary that has an integer as a key and...
Using python. 1. How to create a dictionary that has an integer as a key and a byte as a value? the dictionary keys must contain integers from 0 to 255. It should be similar to UTF-8. When we enter an integer, it should return 1 byte. 2. Create a function when a user gives 1 byte, it should return the key from the previous dictionary.
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents: Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 8: Assignment 1 # ************************************************* #...
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
python pls create a function party_place: that search the dictionary and figure out where they party...
python pls create a function party_place: that search the dictionary and figure out where they party in that day. For example def party_place(dict2: dict, date: (int,int,int)): dict1= {'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output print(party_place(dict1, (2000,5,20,720)) = ['fire1', 'fire2'] print(party_place(dict1, (2000,5,21,720)) = ['fire1'] print(party_place(dict1, (2000,5,22,720)) = []
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT