Question: this is python 3 question in the original flashcard problem, a user can ask the program to show an entry picked randomly from a glossary.

this is python 3 question

in the original flashcard problem, a 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.

A sample session could run as follows:

Enter s to show a flashcard and q to quit: s

Define: word1

Press return to see the definition

definition1

Enter s to show a flashcard and q to quit: s

Define: word3

Press return to see the definition

definition3

Enter s to show a flashcard and q to quit: q

The flashcard program is required to be extended as follows:

Box 1 Specification of extended problem

After every definition is shown, the user is asked whether they knew that definition. If they answer yes, the program informs them that the entry will not be shown again. It then removes that entry from the glossary and tells the user how many entries remain. Apart from these differences the program behaves like the original version.

A sample dialogue could run as follows. The additional dialogue is underlined.

Enter s to show a flashcard and q to quit: s

Define: word3

Press return to see the definition

definition3

Did you know the definition? Enter y for yes: n

Enter s to show a flashcard and q to quit: s

Define: word3

Press return to see the definition

definition3

Did you know the definition? Enter y for yes: y

Now you know the definition that flashcard will be removed

2 cards remain

Enter s to show a flashcard and q to quit: q

Box2

As you work through part (a) of this question you should keep a notebook. You will need this for your answer to part (a)(vi). This should be very brief: it is simply a record of your personal experience while working on the task and what you feel you have learned from it.

In your notebook we suggest that you record the following information

How

A brief description of how you went about the task.

Resources

What documentation if any you consulted (including course materials and any online sources) and which you found most useful. There is no need for full references, just note the source, and in the case of the course materials what the relevant part and section or activity was.

Difficulties

Anything you found difficult about the task, and how you dealt with it.

Lessons learnt

Anything you learned from the task that would be useful if you faced a similar problem in the future.

There is more than one way to solve the extended problem but the approach we ask you to follow for this TMA begins by modifying the part of the program that shows the flashcard.

a.

o i.The algorithm developed for this in

>> show flashcard

Choose a random entry from the glossary

Print this entry to the screen

In response to the user pressing return, print the definition of the entry

o Begin by copying this algorithm. Then add the further steps needed to solve the extended problem specified in Box 1. All the steps you add should follow the existing ones. Your additional steps should be written in English and not use any Python code. Information on how to delete a dictionary entry in Python is given later, but not needed to answer this part.

Note that Box 1 ignores the possibility of the glossary becoming empty and your algorithm should do the same for now. How to deal with the possibility of an empty glossary will be considered in Part (iv).

o ii.Translate your algorithm into Python code. Use the first complete version of the flashcard program; a copy is included in the download for this below at the bottom.

o In the next few question parts, you will be amending this file. You will only have to submit the final amended file (as per the instruction in Part v.).

The function show_flashcard() shows the flashcards, this is where you should make all the changes.

Translating the algorithm into Python code requires entries to be removed from the glossary when appropriate. Use the following information about the Python deloperation to remove entries from a Python dictionary.

Box 3 The Python del operation.

A dictionary entry can be removed using the Python del operation.

If sample_key is a key in the dictionary sample_dictionary, then the entry for sample_key can be removed as follows:

del sample_dictionary[sample_key]

In this example, using the shell, key entry 2 is removed from my_dictionary:

>>> my_dictionary = {1:'item 1', 2: 'item 2', 3: 'item 3'}

>>> my_dictionary

{1: 'item 1', 2: 'item 2', 3: 'item 3'}

>>> del my_dictionary[2]

>>> my_dictionary

{1: 'item 1', 3: 'item 3'}

o iii.When you have modified the show_flashcard() function test it by calling it several times in the shell. Remember to first run the program and only after that use the shell to call the function.

Debug the code and/or algorithm as necessary. If you need to make modifications you should record them in your notebook.

Once you have the function working correctly, run the whole program and test it with a variety of user inputs. Copy a test dialogue into your Solution document that shows the user answering that they have seen a definition before and the program responding appropriately.

o iv.Once you have the show_flashcard() function working correctly you can return to the issue of what should happen if the glossary becomes empty. This can be addressed by a single change. This change is to the part of the program that implements the interactive loop (not to the show_flashcard() function). Make this change to the part of the program that implements the interactive loop, and then run the program again to test it. Copy a test dialogue that shows the program quitting when the number of remaining entries reaches zero, and paste it into your Solution Document.

o v.Next make changes to the docstrings for the function and for the program as a whole, to reflect the changes.

Save your final version of the Python program and submit it as

o vi.Also copy the notebook you have kept for this question into the corresponding part of your Solution Document.

b.Suggest one further small extension or improvement of your own to the flashcard program. Outline what the extension does and include any additional algorithm step(s). You are not required to implement the code, although of course you may do so if you choose. Your answer to this part should be no longer than 150 words, including the added algorithm steps.

the code is below

# Question 3, Part (a), ii, iv, and v

""" This flashcard program allows the user to ask for a glossary entry. In response, the program randomly picks an entry from all glossary 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 *

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!