[Tutor] Dictionaries - Using 1 Key:Value to find another
Al Stern
albstern at gmail.com
Sun Dec 12 02:13:34 CET 2010
Ah. Turns out I was just sloppy and/or stupid. I realized I had another
error once I fixed the '==' part.
My new code which seems to work is...
elif choice == "8":
print ("Find the grandson of a person in the list.")
grandfather = input("Which father do you want to look up to see if
he is a grandfather? ")
if grandfather in pairs:
father = pairs[grandfather]
grandson = pairs[father]
print (grandfather, "is the grandfather of", grandson, ".")
else:
print ("\nSorry.", grandfather, "is not a grandfather. Try
again.")
Thanks all.
_________________
www.electronsbaseball.com
-----Original Message-----
From: David [mailto:bouncingcats at gmail.com]
Sent: Saturday, December 11, 2010 6:35 PM
To: Al Stern
Cc: tutor at python.org
Subject: Re: [Tutor] Dictionaries - Using 1 Key:Value to find another
On 12 December 2010 11:10, Al Stern <albstern at gmail.com> wrote:
>
> I thought father got defined in the
>
> father == pairs[grandfather]
> line. I have tried it a couple different ways but always get the father
is
> not defined error once I enter the name.
I only glanced at your code, but maybe you have some typos there:
father == pairs[grandfather]
for father in pairs:
grandson == pairs[father]
should probably be
father = pairs[grandfather]
for father in pairs:
grandson = pairs[father]
Try that.
More information about the Tutor
mailing list