Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to add part of the code so if the definition is correct to the word and the user puts YES then they are

I need to add part of the code so if the definition is correct to the word and the user puts YES then they are told that's correct.

if the definition is correct to the word and the user puts NO then they are told that's incorrect.

if the definition isn't correct to the word and they put NO then they are correct.

if the definition isn't correct to the word and they put YES then they are incorrect.

THE PROVIDED CODE IS BELOW AND I NEED TO ADD THE ABOVE TO IT

# glossaryFlashCards.py

""" TM112 20J TMA03 Q2 solution code Richard Walker 08/04/2020 """

from random import *

def show_flashcard(): """ The user is shown a random glossary entry, together with a definition that is not necessarily correct, and asked to say whether the definition is correct (Y) or not (N).

They are then told whether their response was 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 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."""

""" 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions