Member Avatar for the_mia_team

Write a Python program that creates a dictionary of son-father pairs-you can make the pairs with fictional names for fun. Your program should populate this dictionary with the son-father pairs
you made up.

Your program should present the user a menu with two options. The following is an example:

Father Finder
0 - Quit
1 - Find a Father

A user input of 0 should end the program. A user input of 1 should cause the program to prompt
the user for the name of a son. If the dictionary contains the son-father pair, the program should
display the father. Otherwise, the program should tell the user it does not know.


My program code below, I got this, entering 0 works, but entering a run just repeats the enter a number choice option, anyone help me out to make it enter a name when entering 1?
-----------------------------------------------------------------------------------------

pairs = {"Jeremy": "Jerome",
"Jason": "Fred",
"Joe" : "Fred",
"Alayna" : "Tom",
"Jay" : "Jerome",
"April" : "Tom"}


choice = None

while choice != "0":

choice = raw_input(
"Please Enter a Number Choice: ")

# Finish

if choice == "0":

print "I guess you are done."

# get a definition

elif choice == "1":
choice = raw_input("Please enter a Name: ")

print "\n This is your current list \n\n", pairs


else:

print "\nI can't do that!", pair, "doesn't exist in the dictionary."

print\
"""

Father Finder


0 - Quit

1 - Find a Father

"""

Member Avatar for snippsat

Use code tag next time,not quote tags.
Look at this code ande try to write the rest(if-else)

pairs =\ {"Jeremy": "Jerome", "Jason": "Fred", "Joe" : "Fred", "Alayna" : "Tom", "Jay" : "Jerome", "April" : "Tom"} def find_father(): print "\n This is your current list \n\n", pairs.keys() #We print only sons names pass def main(): '''Main menu and info ''' while True: print 'Father finder' print '(1) 1 - Find a Father' print '(q) Quit' choice = raw_input('Enter your choice: ') if choice == '1': find_father() elif choice == 'q': return else: print 'Not a correct choice:', choice if __name__ == '__main__': main()
Member Avatar for the_mia_team

still cant figure out where to go from there

Member Avatar for snippsat

Hint.

>>> choice_name = 'Jay' >>> if choice_name in pairs: ... print 'Father name is %s' % pairs[choice_name] ... Father name is Jerome >>>
Member Avatar for the_mia_team

i dunno im lost, i tried multiple things and jsut getting no where lol

Member Avatar for snippsat

Ok here you go,read a little more about dictionary an basic stuff;)

pairs =\ {"Jeremy": "Jerome", "Jason": "Fred", "Joe" : "Fred", "Alayna" : "Tom", "Jay" : "Jerome", "April" : "Tom"} def find_father(): print "\n This is your current list \n\n", pairs.keys() #We print only sons name choice_name = raw_input("Please enter a Name: ") if choice_name in pairs: print 'Father of %s is %s ' % (choice_name, pairs[choice_name]) else: print 'Name not in database' raw_input("\nTrykk enter for meny\n") def main(): '''Main menu and info ''' while True: print 'Father finder' print '(1) Find a Father' print '(q) Quit' choice = raw_input('Enter your choice: ') if choice == '1': find_father() elif choice == 'q': return else: print 'Not a correct choice:', choice if __name__ == '__main__': main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.