On 12 December 2010 07:10, Al Stern <albst...@gmail.com> wrote:
> This was another execise in my book. Following is my code for a program > that uses dictionaries to find and edit pairs of fathers and sons. The > program works right up to the final step which is to find out if any given > father is actually a grandfather to someone else in the dictionary. I set > up multiple generations in the dictionary so there would be available > matches. > > 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] > for father in pairs: > grandson == pairs[father] > print (grandfather, "is the grandfather of", grandson, ".") > else: > print ("Sorry.", grandfather, "is not a grandfather. Try > again.") > > > > input ("\n\nPress the enter key to exit.\n") > > Choice 8 gives me the following error... > > Traceback (most recent call last): > File "C:\Users\Public\Documents\My Python programs\father_son.py", line > 105, in <module> > father == pairs[grandfather] > NameError: name 'father' is not defined > > 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'm sure somebody has beaten me to it, but: You have used "==" rather than "="
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor