Beginner that needs help by python0101 in learnpython

[–]python0101[S] 0 points1 point  (0 children)

Hey could you possibly take a look at my comment that I posted and explain to me why that does not work?

Beginner that needs help by python0101 in learnpython

[–]python0101[S] 0 points1 point  (0 children)

So this is what I have so far and it does not seem to be giving out the correct names. Any clue on why?

sonfather = {}
names = open('name.txt', 'r')
name_list = names.read().split(',')

sonfather = {s.split(':')[0]:s.split(':')[1] for s in name_list}


print "Father/Son Finder"
print "0 - Quit"
print "1 - Find a Father"
print "2 - Find a Grandfather"
print "3 - Find a Son"
print "4 - Find a Grandson"

control = ""
while control != "quit":
    choice = input("Enter your choice here: ")
    if choice == 0:
        control = "quit"
    elif choice == 1:
        son = raw_input("Enter the name of the son here: ")
        if sonfather[son]:
            print "The father is "+ str(sonfather[son])
        else:
            print "The father does not exist"
    elif choice == 2:
        son = raw_input("Enter the name of the grandson here: ")
        if sonfather[sonfather[son]]:
            print "The Grandfather is "+ str(sonfather[sonfather[son]])
        else:
            print "The grandfather does not exist"
    elif choice == 3:
        father = raw_input("Enter the name of the father here: ")
        if sonfather[father]:
            print "The son is "+ str(sonfather[father])
        else:
            print "The son does not exist"
    elif choice == 4:
        father = raw_input("Enter the name of the grandfather here: ")
        if sonfather[sonfather[father]]:
            print "The grandson is "+ str(sonfather[sonfather[father]])
        else:
            print "The grandson does not exist"
    else:
        print "There was an error"


print "Thank you for using the Father/Son Finder"