My assignment is:
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 list and as you do print everything you know about each pet.
What I have so far:
Output so far:
Pet Name:
Type: Dog
Pet Owner: Joe
Pet Name:
Type: Cat
Pet Owner: Gail
Pet Name:
Type: Bird
Pet Owner: Paul
Pet Name:
Type: Snake
Pet Owner: Stan
My Question:
What do I need to add to my code to have the output include the Pet Name.
Desired Output:
Pet Name: Rover
Type: Dog
Pet Owner: Joe
Pet Name: Blackie
Type: Cat
Pet Owner: Gail
Pet Name: Polly
Type: Bird
Pet Owner: Paul
Pet Name: Seth
Type: Snake
Pet Owner: Stan
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 list and as you do print everything you know about each pet.
What I have so far:
Code:
rover = {'type': 'dog', 'owner': 'joe'}
blackie = {'type': 'cat', 'owner': 'gail'}
polly = {'type': 'bird', 'owner': 'paul'}
seth = {'type': 'snake', 'owner': 'stan'}
pets = [rover, blackie, polly, seth]
for pet in pets:
print("\nPet Name:", "\nType:", pet['type'].title(), "\nPet Owner:", pet['owner'].title())
Pet Name:
Type: Dog
Pet Owner: Joe
Pet Name:
Type: Cat
Pet Owner: Gail
Pet Name:
Type: Bird
Pet Owner: Paul
Pet Name:
Type: Snake
Pet Owner: Stan
My Question:
What do I need to add to my code to have the output include the Pet Name.
Desired Output:
Pet Name: Rover
Type: Dog
Pet Owner: Joe
Pet Name: Blackie
Type: Cat
Pet Owner: Gail
Pet Name: Polly
Type: Bird
Pet Owner: Paul
Pet Name: Seth
Type: Snake
Pet Owner: Stan
Comment