Question
Word_List_Flashcard.py # Starter file for TM112 2022J TMA03 Q2 This flashcard program allows the user to ask for a word_list entry. In response, the
Word_List_Flashcard.py
# Starter file for TM112 2022J TMA03 Q2
""" This flashcard program allows the user to ask for a word_list entry. In response, the program randomly picks an entry from all word_list entries. It shows the entry. After the user presses return, the program shows the definition of that particular entry. 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. Show the definition when the user presses return. """ random_key = choice(list(word_list)) print('Define: ', random_key) input('Press return to see the definition') print(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.')
In the original flashcard problem, the cards are designed to help a user improve their familiarity with a glossary of terms. The user can ask the program to show an entry picked randomly from a glossary. When the user presses return, the program shows the definition corresponding to that entry. The user is then given the option of seeing another entry or quitting. Another common use of flashcards is to help someone learning a language practise their vocabulary. Someone learning French, for example, might have a set of cards with English words on one side and their French equivalents on the other. They pick a random card, read one side and then see if they can remember what's on the other side, as illustrated in Figure 1. 39571906 Figure 1 A flashcard with an English word on one side and its French equivalent on the other. In this question you will adapt a version of the glossary flashcards program to become an English to French vocabulary tester. Box 1 - the problem The program should allow the user to ask for a word list entry. In response, the program should randomly pick an entry from the word list. It should display the English word and invite the user to enter the French equivalent. After the user enters their answer, the program should check the answer. If it is correct the program should tell the user; otherwise, if the answer is wrong the program should tell the user and inform them of the correct answer. The user should be able to repeatedly ask for an entry and also have the option to quit the program instead of seeing another entry.
A sample session might run like this:
Enter s to show a flashcard and q to quit: s
What is the French for red: rouge
Correct, well done!
Enter s to show a flashcard and q to quit: s
What is the French for yellow: vert
Sorry, the answer is jaune
Enter s to show a flashcard and q to quit: s
What is the French for white: blanc
Correct, well done!
Enter s to show a flashcard and q to quit: s
What is the French for yellow: jaune
Correct, well done!
Enter s to show a flashcard and q to quit: q
>>>
For the purposes of developing the program we will use a small word list with just six entries: the name of a colour in English, and its French equivalent.
A. We have provided a Python file Word_List_Flashcards.py that you should work from when answering this question. If you read this program and run it you will find it is exactly the same as Flashcards_First_Complete_Version.py, except that we have replaced the glossary dictionary and all references to it with a dictionary word_list, which is an English-French word list, and added a comment in the show_flashcard() function.
i. Write your algorithm for the following section in Box 1, reproduced here for convenience. The program should allow the user to ask for a word list entry. In response, the program should randomly pick an entry from the word list. It should display the English word and invite the user to enter the French equivalent. After the user enters their answer, the program should check the answer. If it is correct the program should tell the user, otherwise, if the answer is wrong the program should tell the user and inform them of the correct answer. Your algorithm should provide a similar level of detail to the show flashcard algorithm in Subsection 2.5.2 of Block 3 Part 2. Your algorithm should resemble the one shown there, except that the user will need to do more than just press return, and the program will have to evaluate the user response and act accordingly.
ii. Discuss briefly how you will test the program. Only a short answer is required, and you do not need to give examples, only describe what approach you will follow.
iii. Now you will implement your algorithm as Python code, modifying the provided Python program Word_List_Flashcards.py. Complete the new version of show_flashcard() by modifying the code so it implements the algorithm you produced in part i. Also modify the docstring for the show_flashcard() function and the docstring for the program as a whole, to take account of the changed functionality and behaviour. The changes you make to the function show_flashcard() should be consistent with the algorithm you gave in part i. You should use only the Python features that are introduced in the module. If you consider there is a compelling reason why you need features not taught in TM112 you must explain your reasons, otherwise marks may be lost. If you are unable to get the program working correctly, you should still copy your code into your Solution document, with a brief explanation of how the results are different from what you intended.
B. Suggest one further small extension or improvement of your own to the modified flashcard program. Outline what the extension or improvement does and briefly describe any additional sub-problem(s) that would need to be added to the initial decomposition. Note that you are only required to describe your further extension or improvement, you do not need to implement it in code.
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