Question
Below my python script has been started. I need to implement this algorithm into code in the section it says insert code here. iii)
Below my python script has been started.
I need to implement this algorithm into code in the section it says "insert code here. "
iii) 1- The Word is displayed with definition
2 - user decides if definition is correct or incorrect
2a) if user is correct about definition then Display Right
3 - otherwise
3a) Display Wrong
4- print correct word and definition
from random import *
def show_flashcard():
"""
This prgroam allows the user to ask for a glossary entry.
In response, the program will randomly pick an entry from
the glossary. Once the deffination of the glossary word is displayed the user
will have to decide if the definition is correct (Y) or incorrect (N).
They are then told if their response is right or wrong.
"""
""" Do not change this first section."""
# Get glossary keys.
keys = list(glossary)
# Choose two distinct keys at random.
sample_keys = sample(keys, 2)
# The first is the entry that will be displayed.
# The definition corresponding to this is the right one.
random_entry = sample_keys[0]
# The second entry will not be displayed.
# The definition corresponding to this is the wrong one.
other_random_entry = sample_keys[1]
# This variable will control whether the user is
# shown the right definition or the wrong one.
right_or_wrong = choice(['right', 'wrong'])
# Pose question.
print('Here is a glossary entry:')
print(random_entry)
print('Here is a possible definition for it:')
if right_or_wrong == 'right':
print(glossary[random_entry])
else:
print(glossary[other_random_entry])
""" End of first section."""
""" Insert your code below.""" <----- NEED HELP WITH THIS PART
""" Do not change anything beyond this point """
# Set up the glossary
glossary = {'word1':'definition1',
'word2':'definition2',
'word3':'definition3'}
# 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.')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started