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: - 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())
-
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
I would include it in the dictionary rover = {'name':'rover', 'type': 'dog', 'owner': 'joe'}
3 1474 dwblas 626
Recognized Expert Contributor
I would include it in the dictionary rover = {'name':'rover', 'type': 'dog', 'owner': 'joe'}
You could also simply include the item you're iterating. - ...("\nPet Name:", pet, "\nType:", pet['type'].title()...
I'm not sure if your assignment is suggesting you use one way or the other, but figured I'd point out a second option.
dwblas 626
Recognized Expert Contributor
You could also simply include the item you're iterating. - ...("\nPet Name:", pet, "\nType:", pet['type'].title()...
That would print the entire contents of each dictionary as pets is a list of dictionaries.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Santanu Chatterjee |
last post by:
Hello everybody,
I am very new to python. I have a query about
list in python.
Suppose I have a list
a = ,5,6,7,,11,12]
I want to know if there is any simple python
facility available that...
|
by: Bart Simpson |
last post by:
Hi,
I want to control 'Scheduled Tasks' in Windows 2003 by python program.
But I couldn't find any Python module about win32 'Scheduled Tasks'.
I could find only Perl module about it. (see...
|
by: Xah Lee |
last post by:
© # -*- coding: utf-8 -*-
©
© # in Python, there's a special type of
© # data structure called keyed list. it
© # is a unordered list of pairs, each
© # consists of a key and a value. It is
©...
|
by: Scheol Service |
last post by:
---------- Forwarded message ----------
From: Scheol Service <scheols@gmail.com>
Date: Nov 29, 2006 10:57 PM
Subject: Python Question About Compiling.
To: mailto:python-list@python.org
Im...
|
by: texas22 |
last post by:
I am new to programming and am trying to teach myself python. I have two questions how do you use a for loop to print out the lines from a list with the line numbers then the word and then I also...
|
by: marketing-python-bounces |
last post by:
This mailing list has been retired. Please use the new Python
Advocacy mailing list instead:
http://mail.python.org/mailman/listinfo/advocacy
Thanks!
|
by: antar2 |
last post by:
Hello,
I am a beginner in Python and am not able to use a list element for
regular expression, substitutions.
list1 =
list2 =
Suppose that I want to substitute the vowels from list2 that...
|
by: cna |
last post by:
Hi all and one,
how may i learn python. is there any other website except python.org
|
by: anonymous |
last post by:
1 Objective to write little programs to help me learn German. See code
after numbered comments. //Thanks in advance for any direction or
suggestions.
tk
2 Want keyboard answer input, for...
|
by: supa |
last post by:
Hi. I've coded some stuff a long time ago, and didn't have reason to take up programming until now. I've learned Python 'on-the-go' and now ran into the idea of avoiding global variables of any kind....
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |