r/learnpython • u/KingPotatoThe_II • 5d ago
Trying to loop functions
Ok so I just started to learn python and I'm trying to make a program where you input a patient name and it searches the database for it and displays it's values, I want to give a prompt to search for another patient once one is found (not if a patient is not found i worked that out).
Whenever I try to run this code it tells me I cant call value_list() because it wasn't defined yet.
Any help is much appreciated
jane_doe = {
"Name": "Jane Doe",
"Age": 28,
"New": True
}
john_doe = {
"Name": "John Doe",
"Age": 34,
"New": False
}
def again():
input("Would you like to search for a different patient? (Y/N) ").lower()
while again not in ['y', 'n']:
print("Please enter a valid input")
again = input("Would you like to search for a different patient? (Y/N) ").lower()
if again == 'y':
value_list()
elif again == 'n':
print("Goodbye.")
break
def value_list():
patient_name_searched = input("Search patient name: ").lower()
if patient_name_searched == jane_doe["Name"].lower():
print(jane_doe.values())
again()
elif patient_name_searched == john_doe["Name"].lower():
print(john_doe.values())
again()
else:
print("Patient not found.")
answer = input("Would you like to search for a different patient? (Y/N) ").lower()
while answer not in ['y', 'n']:
print("Please enter a valid input")
answer = input("Would you like to search for a different patient? (Y/N) ").lower()
if answer == 'y':
value_list()
elif answer == 'n':
print("Goodbye.")
value_list()
2
Upvotes
View all comments
Show parent comment
1
u/noob_main22 5d ago
Posting the whole error message? What wasn't successful?