Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question is concerned with an extension to the flashcard problem you studied in Block 3 Part 2. In the original flashcard problem, a user

This question is concerned with an extension to the flashcard problem you studied in Block 3 Part 2.

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

As well as being offered a choice between seeing a flashcard or quitting, the user is offered the option to add a new glossary entry.

If the user picks this option they are first asked to enter the new word, and then the corresponding definition. The program then adds the word and definition to the glossary as a new entry and informs the user that this has been done.

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, a to add a new card, or q to quit: s

Define: word3

Press return to see the definition

definition3

Enter s to show a flashcard, a to add a new card, or q to quit: a

Enter the new word: some word

Enter the definition: some definition

New entry added to glossary

Enter s to show a flashcard, a to add a new card, or q to quit: q

Box 2 Keeping a notebook

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 of solving the extended problem but the approach we ask you to follow for this TMA starts by addressing the sub-problem of adding a new glossary entry.

  • a.

    • i.Begin by writing an algorithm for the subproblem, add flashcard, which carries out the steps necessary if the user picks the option of adding a single new glossary entry, as described in Box 1 above, and repeated here for convenience.

      they are first asked to enter the new word, and then the corresponding definition. The program then adds the word and definition to the glossary as a new entry and informs the user that this has been done.

      At this stage no looping is involved and the steps of the algorithm only need to do what is asked for in the paragraph above, and nothing more.

      The steps of your algorithm must be written in English and not use any Python code. The algorithm should be high-level and at a similar level of detail to the solution to Activity 2.24 of Block 3 Part 2, where an algorithm is given for show flashcard.

    • ii.Next you will translate your algorithm into Python code.

      Begin with the first complete version of the flashcard program, a copy of which is included in the download for this TMA as Q3.py. Save a copy this program as Q3_OUCU.py (where OUCU is your OU computer username, e.g. abc123).

      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 instructions in Part vii).

      Add a new function add_flashcard() to the program, which translates into Python the steps of the algorithm you wrote in part i. You should insert the new function just after the show_flashcard() function.

      Make sure you write a suitable docstring for the function.

      How to add a new item (i.e. an entry) to a dictionary, given a key and a value, is discussed in Subsection 2.1.4 of Block 2 Part 2, and repeated below for convenience.

Box 3 Adding an item to a dictionary

Given a dictionary sample_dictionary, new key sample_key and a new value sample_value, we can add a new entry to the dictionary by using an assignment

sample_dictionary[sample_key] = sample_value

    • iii.When you have modified the add_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.

      Once you have called the function, provided the required inputs, and have been informed that the new entry has been added, you can confirm that the new entry really has been added by entering the name of the dictionary, glossary, and the contents will be displayed.

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

      Copy and paste an example test into your Solution Document. This should show a new entry being added and confirmation that the action was successful.

      Alternatively, if you were unable to get the function working correctly, you should still paste in an example test, and explain briefly how the results are different from what you were expecting.

    • iv.Now you need to make changes to the part of the program that implements the interactive loop, so the user is offered the option of adding a new glossary entry, and if they choose this option the add_flashcard() function is called.

      Once you have made the changes, run the whole program. Copy a test dialogue into your Solution document to show the user selecting the option to add a new entry, then being prompted for the word and its definition, then being informed that the new entry has been added.

      Alternatively, if you were unable to produce a test dialogue because you could not get the program to function as intended, you should briefly explain how a successful test dialogue would look.

    • v.Next modify the docstring for the program as a whole to reflect the changes you have made.

      Save your final version of the Python program and submit it as Q3_OUCU.py(where OUCU is your OU computer username, e.g. abc123) in your TMA zip file.

      Also paste a copy of your final Python program into your solution document as text.

    • vi.Finally, copy the notebook you have kept for this question into the corresponding part of your Solution Document.

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Explain how the month of October is associated with heuristic.

Answered: 1 week ago