[Tutor] python dictionaries

Carroll, Barry Barry.Carroll at psc.com
Sat Jan 6 01:49:08 CET 2007


> -----Original Message-----
> Message: 7
> Date: Fri, 05 Jan 2007 15:43:56 -0800
> From: "Raven Of Night Raven Of Night" <raistlen117 at msn.com>
> Subject: [Tutor] python dictionaries
> To: tutor at python.org
> Message-ID: <BAY108-F34D4353E7ACCA79224BAC6E8BF0 at phx.gbl>
> Content-Type: text/plain; format=flowed
> 
> Hi, there was this two step program I was working on but i can only
> complete
> the first step.
> 
> - - Write a Who's Your Daddy? program that lets the user enter the
name of
> the male and produces the name of his father. Allow the user to add,
> replace, and delete father son pairs. The program should also allow
the
> user
> to get a list of all son, fathers, or father son pairs.
> 
> I made a dictionary:
> family = { "Wane Wilright" : "Dan Wilright",
>            "Michal Zheng" : "Tsu Zheng",
>            "Art Core" : "Vandalee Core",
>            "John Wane" : "Calvin Wane" }
> 
> and was able to complete the rest of the program.
> 
> 
> Then I was asked to improve the program:
> - - Improve the Who's Your Daddy program by adding a choice that lets
the
> user enter a name and get back a grandfather. Your program should
still
> use
> one dictionary of son-father pairs. Make sure to include several
> generatios
> in your dictionary so that a match can be found.
> 
> I don't understand, dictionarys only allow two elements so how can you
> include several generations in the dictinoary... could you perhaps put
a
> dictinoary inside a dictionary? I don't understand how you would do
the
> second part.
> 
> _________________________________________________________________
> The MSN Entertainment Guide to Golden Globes is here.  Get all the
scoop.
> http://tv.msn.com/tv/globes2007/?icid=nctagline2
> 
> 
> 
> ------------------------------
> 
> Message: 8
> Date: Sat, 6 Jan 2007 00:02:22 +0000
> From: "Adam Bark" <adam.jtm30 at gmail.com>
> Subject: Re: [Tutor] python dictionaries
> To: "Raven Of Night Raven Of Night" <raistlen117 at msn.com>
> Cc: tutor at python.org
> Message-ID:
> 	<be4fbf920701051602t2ff3fb74m30eb7b9d58426683 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> On 05/01/07, Raven Of Night Raven Of Night <raistlen117 at msn.com>
wrote:
> >
> > Hi, there was this two step program I was working on but i can only
> > complete
> > the first step.
> >
> > - - Write a Who's Your Daddy? program that lets the user enter the
name
> of
> > the male and produces the name of his father. Allow the user to add,
> > replace, and delete father son pairs. The program should also allow
the
> > user
> > to get a list of all son, fathers, or father son pairs.
> >
> > I made a dictionary:
> > family = { "Wane Wilright" : "Dan Wilright",
> >            "Michal Zheng" : "Tsu Zheng",
> >            "Art Core" : "Vandalee Core",
> >            "John Wane" : "Calvin Wane" }
> >
> > and was able to complete the rest of the program.
> >
> >
> > Then I was asked to improve the program:
> > - - Improve the Who's Your Daddy program by adding a choice that
lets
> the
> > user enter a name and get back a grandfather. Your program should
still
> > use
> > one dictionary of son-father pairs. Make sure to include several
> > generatios
> > in your dictionary so that a match can be found.
> >
> > I don't understand, dictionarys only allow two elements so how can
you
> > include several generations in the dictinoary... could you perhaps
put a
> > dictinoary inside a dictionary? I don't understand how you would do
the
> > second part.
> 
> 
> Hopefully this will make sense to you as I don't want to give the
whole
> game
> away.
> A grandfather is just a father's father. If you don't get it still
then
> I'll
> make it a bit
> more obvious.
> HTH,
> Adam.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
>
http://mail.python.org/pipermail/tutor/attachments/20070106/df0a537b/att
ac
> hment.htm

Think of it this way:

	My name is Barry.
	My father's name is Jim.
	Jim's father's name is Walt (***my grandfather***).

How can you use your dictionary to emulate that?

Good luck.

Regards,
 
Barry
barry.carroll at psc.com
541-302-1107
________________________
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed





More information about the Tutor mailing list