Question: Question 2 (23 marks) You must give a word count for any question with a maximum word limit. This question tests your understanding ofBlock 3

Question 2 (23 marks)

You must give a word count for any question with a maximum word limit.

This question tests your understanding ofBlock 3 Part 2and, more generally, the problem-solving and Python programming skills that are covered by the module. The question is concerned with an extension to the flashcard problem you studied in Block 3 Part 2.

You may find it useful to read through the whole question before starting to answer it.

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

Although this is a useful learning aid, the user plays a rather passive role, in that all they do is view the definition. The extended problem described below goes further. In this new version they are presented with two definitions in random order. Only one definition is correct, and they are asked to identify which one it is by entering either 1 or 2. They are then told whether their choice was correct or not.

Box 1 - Specification of extended problem

The user can ask to see a random flashcard.

They are then shown a glossary entry, together with two definitions. One definition is correct and the other incorrect, and they are shown in random order. The user is then invited to indicate which definition they believe is the correct one by typing either 1 or 2. They are then told whether their choice was correct or not.

The user can repeatedly choose to either see a random entry, as described above, or choose an option to quit the program.

A sample dialogue might run as follows:

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

Here is a glossary entry: word2

Here are two possible definitions:

1. definition3

2. definition2

Which definition is correct? Enter either 1 or 2. 1

incorrect

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

Here is a glossary entry: word3

Here are two possible definitions.

1. definition1

2. definition3

Which definition is correct? Enter either 1 or 2. 2

correct

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

For the purposes of developing the program we have used a small glossary with just three dummy entries, chosen so we can easily see which definitions are the right ones.

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:

HowA brief description of how you went about the task.ResourcesWhat 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.DifficultiesAnything you found difficult about the task, and how you dealt with it.Lessons learntAnything you learned from the task that would be useful if you faced a similar problem in the future.

  • a.
  • i.First write an algorithm for the following subproblem, taken from Box 1.
  • They [the user] are then shown a glossary entry, together with two definitions. One definition is correct and the other incorrect, and they are shown in random order. The user is then invited to indicate which definition they believe is the correct one by typing either 1 or 2. They are then told whether their choice was correct or not.
  • The steps of your algorithm must be written in English, not Python code. The algorithm should be high-level and at a similar level of detail to the solution toActivity 2.24of Block 3 Part 2, where an algorithm is given for the original version ofshow flashcard().
  • Below we have written the start of the algorithm. You should copy this and then add the remaining steps.
  • >> Show flashcard
  • Choose a random glossary key
  • Choose another random glossary key
  • Display the random glossary key
  • Decide randomly what order the definitions corresponding to the random keys will be displayed in.
  • ...
  • ii.Implementing the part of the algorithm that you added will involve using one of the patterns taught in TM112 Block 1. State the name of the pattern and the pattern number. You will probably find it useful to consult theProblem solving and Python quick reference.
  • iii.To apply your chosen pattern you now need to instantiate it, that is replace the general values used in the pattern by the specific ones needed for the solution of the current problem. You should assume that the user will always enter either 1 or 2, so you will not require an interactive loop. Include your instantiation of the pattern in your Solution Document.
  • iv.Discuss briefly how you will test the program, bearing in mind that the entries will be chosen at random, as will the order in which the correct and incorrect answers are displayed, and you have no control over this. So, you need to think what you need to do in order to convince yourself the program is working correctly. Only a brief answer is required, and you do not need to give examples, only describe what approach you will follow.
  • v.Now you will implement the instantiated pattern as Python code.
  • We have provided a starter script which is included in the download for this TMA as Q2.py. Begin by saving a copy of the provided program asQ2_OUCU.py(where OUCU is your OU computer username, e.g. abc123).
  • The starter script is a modified version of the first complete version of the flashcard program as developed in Block 3 Part 2. In the definition ofshow_flashcard()we have provided additional code that implements the first steps of the algorithm, as given in Part (i) above.
  • Choose a random glossary key
  • Choose another random glossary key
  • Display the random glossary key
  • Decide randomly what order the definitions corresponding to the random keys will be displayed in.
  • Complete the new version ofshow_flashcard()by adding code, where indicated by comments already in the code, that will implement the algorithm you produced in Part iii. You should add your own comments to make it clear how the code you have written corresponds to the steps in the algorithm.
  • Also make sure you write a suitable docstring for the modified function.
  • Copy the completedshow_flashcard()function into your Solution Document. Also include your completed.pyfile in your TMA zip file.
Notes

You should aim to use only the Python features that are introduced in the module.If you decide to use techniques or language features that TM112 does not cover, you must give a justification for your decisions, otherwise marks will be lost.

You should not make any changes to any other part of the program; all the code you add must be where indicated.

If you were unable to get the function working correctly, you should still explain briefly how the results are different from what you were expecting.

  • vi.Finally, copy the notebook you have kept for this question into the corresponding part of your Solution Document.
  • (19 marks)
  • b.Suggest one further small extension or improvement of your own to the modified flashcard program. Outline what the extension does and briefly outline what additional algorithmic steps would be needed. Note that you are only required to describe the extension, as specified above, and do not need to implement it in code.
  • The maximum word count for this part of the question is 150 words, including added algorithm steps.
  • (4 marks)

(Total 23 marks)

PREVIOUS

Question 2 (23 marks)

NEXT

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 Programming Questions!