this is my program and in the def show_flashcard part the program seems to be ignoring my if statement to see if the random word and the users input match
# Starter file for TM112 2022J TMA03 Q2
"""
This flashcard
In response, the program randomly picks an entry from all word_list
entries. It shows the entry. then asks the user to put in the English translation
Aif the users answer is correct correct will be printed on screen if is wrong
incorrect and the correct answer will be printed on screen
The user can repeatedly ask for an entry and also
has the option to quit the program instead of seeing
another entry.
"""
from random import *
# IMPORTANT
# Q2 (a)(iii) Make changes only to
# -- the docstring for the program as a whole.
# -- the docstring of the show_flashcard() function
# -- the body of the show_flashcard() function.
def show_flashcard():
""" Show the user a random key and ask them
to define it. then asks the user to put in the English translation
if the users answer is correct, correct will be printed on screen if is wrong
incorrect and the correct answer will be printed on screen """
random_key = choice(list(word_list))
user_answer = input(f"What is the French equivalent of {random_key} ? ")
if user_answer == random_key:
print("Correct!")
else:
print(f"Incorrect. The correct answer is {word_list[random_key]}!")
# Set up the word_list
word_list = {'black':'noir',
'red':'rouge',
'yellow':'jaune',
'orange':'orange',
'white':'blanc',
'green':'vert'}
# The 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.')
this is my program and in the def show_flashcard part the program seems to be ignoring my if statement to see if the random word and the users input match
Step by step
Solved in 2 steps