Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6-8. Pets: Make several dictionaries, where the name of each dictionary is the n

ID: 3915723 • Letter: 6

Question

6-8. Pets: Make several dictionaries, where the name of each dictionary is the name of a pet. In each dictionary, include the kind of animal and the owner's name. Store these dictionaries in a list called pets. Next, loop through your lst and as you do print everything you know about each pet. 6-9. Favorite Places: Make a dictionary called favorite places. Think of three names to use as keys in the dictionary, and store one to three favorite places for each person. To make this exercise a bit more interesting, ask some friends to name a few of their favorite places. Loop through the dictionary, and print each person's name and their favorite places. 6-10. Favorite Numbers: Modify your program from Exercise 62 (page 102) so each person can have more than one favorite number. Then print each person's name along with their favorite numbers. 6-11. Cities: Make a dictionary called cities. Use the names of three cities as keys in your dictionary. Create a dictiohary of information about each city and include the country that the city is in, its approximate population, and one fach about that city. The keys for each city's dictionary should be something like country, population, and fact. Print the name of each city and all of the infor mation you have stored about it. 6-12. Extensions: We're now working with examples that are complex enough that they can be extended in any number of ways. Use one of the example pro- grams from this chapter, and extend it by adding new keys and values, chang- ing the context of the program or improving the formatting of the output. MacBook Air F9 ok 5

Explanation / Answer

Language is not specified for the above question, so according to the type of questions, I am providing the answer using python programming language.

6-8. pets:

dog={'kind of animal':'domestic','name of owner':'steve'}

cat={'kind of animal':'domestic','name of owner': 'hannah'}

aligator={'kind of animal': 'reptile','name of owner':'alison'}

pets=[dog,cat,aligator]

for pet in pets:

for key,value in pet.items():

print(key + ' : ' + value)

print(' ')

Description:

In the above answer i have used 3 pets, dog,cat,aligator. I used 3 dictionaries for each of them.

each dictionary has 2 keys namely kind of animal,name of owner and their values respectively.

Then i have stored these 3 dictionaries into a list called as pets.

I have created a nested loop to move through each item of the list and as list is containing dictionary so another for loop is looping through each dictionary, thus printing keys and values from each dictionary.

output:

kind of animal : domestic
name of owner : steve

kind of animal : domestic
name of owner : hannah

kind of animal : reptile
name of owner : alison

___________________________________________________________________________________

6-9. Favorite places:

favorite_places={'pikachu':'New York','charmander':'london','snorlax':'tokyo'}

for key,value in favorite_places.items():

print(key + ' : ' + value)

print('')

Description:

created a dictionary with the name favorite_places added 3 names of my friends pikachu, charmander and snorlax as keys and then i used for loop to print keys and values.

output:

pikachu : New York

charmander : london

snorlax : tokyo

_____________________________________________________________________________________

6-10. favorite numbers

This particular exercise is in relation to the exercise of 6-2 which is not present in the question.

______________________________________________________________________________________

6-11. cities

cities={'tokyo':{'country':'japan','approximate population':'38,305,000','fact':'tokyo skytree is must visit'},'sydney':{'country':'australia','population':'5,131,326','fact':'sydney opera house is must visit'},'madrid':{'country':'spain','population':'3.2 million','fact':'royal palace of madrid must visit'}}

for k1,v1 in cities.items(): # the basic way
print(k1)
for k2,v2 in v1.items():
print(k2 + ' : ' + v2)
print(' ')

Description:

used 3 cities: tokyo,sydney and madrid.

and created a nested dictionary for the description of each city.

As it is a nested dictionary so i have used nested for loop where k1 is the name of the city and v1 is another dictionary which contains the information related to each city.

k2 is the key in regarding to the description of the city and v2 is the value associated with the same.

output:

madrid
country : spain
fact : royal palace of madrid must visit
population : 3.2 million

sydney
country : australia
fact : sydney opera house is must visit
population : 5,131,326

tokyo
country : japan
approximate population : 38,305,000
fact : tokyo skytree is must visit

_________________________________________________________________________________________

6-12. Extensions

kindly suggest the program for extension

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote