r/learnpython • u/KingPotatoThe_II • 12d 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
2
u/Designer-Ad-2136 12d ago
You arent storing your user input. You are using the same name for functions and local variables.
That said, dont let people tell you that python cant have two functions that call eachother. Python runs from top to bottom and it doesnt need to run the function to set it up.