J'ai tout bien dans mon code (je pense) sauf la partie où j'obtiens les noms corrects de mon dictionnaire.Je ne peux pas obtenir les bonnes valeurs de mon dictionnaire. Aucune suggestion?
Mon code est:
studentdirectory = {"Andrew": ["Jane", "John"], "Betsy": ["Ellen", "Nigel"], "Louise": ["Natalie", "Louis"], "Chad": ["Mary", "Joseph"]}
def menu():
print
print ("Enter 1 to retrieve the mother's name of the child.")
print ("Enter 2 to retrieve the father's name of the child.")
print ("Enter 3 to retrieve the name of both parents of the child.")
print ("Enter 0 to quit.")
print
while True:
choice = input("Enter your choice now: ")
if (choice >= 0) and (choice<= 3) and (int(choice) == choice):
return choice
else:
print ("Your choice is invalid. Please try again with options 0 to 3.")
for key in studentdirectory:
mom = studentdirectory[key][0]
dad = (studentdirectory[key][1])
def main():
while True:
choice = menu()
if choice == 0:
break
else:
name = raw_input("Enter the name of the child: ")
if studentdirectory.has_key(name):
if choice == 1:
print "The name of the child's mother is ", mom, "."
elif choice == 2:
print "The name of the child's father is ", dad, "."
else:
print "The name of the child's parents are ", mom, " and ", dad, "."
else:
print "The child is not in the student directory."
main()
Je voudrais garder mon code aussi proche de ce que possible. J'ai juste besoin d'aide pour comprendre comment obtenir des valeurs séparées dans le dictionnaire, parce qu'à l'heure actuelle, pour chaque maman et papa, je ne récupère que les parents de Louise. Comment puis-je réparer ça?? Ceci est le langage Python.
Merci! Ça a marché! – Maddie
@Maddie heureux de vous aider – amow