So I am very new to Python (and this site) and I am trying to create a flashcard loop for my partner to help her with her studies, I have generated a test version without any real terms and definitions (for now) however when I try to use elif or else in create the loop in Python IDLE 3.11 it just states "Invalid syntax" and showing elif or else with a highlighted 'e', here is the test code for reference:
import random
def show_flashcard():
"""Show the user a random key and ask them to define it. Show the definition when the user presses return."""
random_key = choice(list(glossary()))
print('Define: ', random_key)
input('Press return to see the definition')
print(glossary[random_key])
# Set up glossary
glossary = {'word1':'definition1',
'word2':'definition2',
'word3':'definition3'}
# Interactive loop
exit = False
while not exit:
user_input = input('Enter s to show a flashcard and q to quit: ')
if user_input == 'q':
exit = True
elif user_input == 's':
show_flashcard()
else:
print('You need to enter either q or s.')
# Choose a random entry from the glossary
random_word = random.choice(list(glossary.keys()))
# Print the random entry to the screen
print("flashcard:")
print(random_word)
# Wait for the user to press Enter
input("Press Enter to reveal the definition...")
#Print the definition of the entry
print(glossary[random_word])`
I have tested everything before trying to create the loop and it all works, can someone help?
Thank you!
I tried changing the elif and else but no such luck, I don't know any other alternative to this situation.