In: Computer Science
*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.
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!