My program is supposed to record information for athletes in a race. When I select the option to add a score for an athlete, it calls the input_scores function, but then it won't get out of it? Also, for option "b", I want it to display the message that there's no record available if the list athlete_results is empty. I hope I've explained things ok, I am new to programming so any help is appreciated!
menu = """Choose an option:
'a' = Input score
'b' = Display results
'c' = quit
>
"""
athlete_results = []
choice = input(menu).strip().lower()
def input_scores():
name = input("Name: ").strip().title()
country = input("Country: ").strip().title()
time = input("Time: ").strip()
athlete_results.append({
"Name": name,
"Country": country,
"Time:": time
})
def display_results():
for athlete in athlete_results:
name, country, time = athlete_results.values
print(f"{name}| {country}| {time}s")
while True:
if choice == 'a':
input_scores()
elif choice == 'b':
if athlete_results:
display_results()
elif choice == 'c':
break
else:
print("Invalid option!!!")
CodePudding user response:
Move the line
choice = input(menu).strip().lower()
to a line directly after while True:
while True:
choice = input(menu).strip().lower()
in order to have a chance to change the option or quit.