r/learnpython • u/KingPotatoThe_II • 14d 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/Adrewmc 14d ago
So the functions search_for_patient()
Calls the function search_again()
Then has a en error which the variable ‘choice’ not being defined yet.
However, not one of those things is in the code you posted so, there isn’t anything that people can do until you post the code that actually goes wrong.