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'
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
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...
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): should return {'Top': {'Fiora': 1, 'Yasuo':5,'Olaf':3,'Shaco':}, 'Jungle': {'Shaco': 4}, 'Mid': {'Yasuo', 2, 'Fiora': 4,'Olaf':2}, 'Bottom': {'Fiora': 3}, 'Support': {'Olaf': 4}} *******IMPORTANT*************** The result should be alphabetical order.
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.
(Python) I want to use a function called level() that takes a dictionary. Here is a...
(Python) I want to use a function called level() that takes a dictionary. Here is a dictionary with people's job and skill level. dict1 = {'Jame': {'Cleaning': 5, 'Tutoring': 2, 'Baking': 1},Pam': {'Plumbing': 2, 'Cleaning': 5}) like if I called level(dict1), the output will return {'Pam', 'James'} It finds the people's average skill level like for Pam is (2+5)/2=3.5 and sorted descending. How do I do that and how do I do it in only one return statement(using comprehension or...
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 # ************************************************* #...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT