Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Question 2 (23 marks)

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

This question tests your understanding of problem-solving and Python programming skills that are covered by the module. The question is concerned with a variant to the flashcard problem you studied in Block 3 Part 2.

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

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.

In our variant the program is designed to help people who want to learn the symbols for chemical elements. Every element has a symbol, a one or two letter abbreviation used to represent it. For example, the symbol for Hydrogen is H, that for Oxygen O, Calcium Ca, and Silicon Si.

For most elements the symbol is not hard to remember, because the connection between the name of an element and its chemical symbol is fairly obvious, as in the examples above. However, there are eleven elements for which the connection between name and symbol appears rather mysterious, making them hard to learn. For example the symbol for Tungsten is W. The reason for these unexpected symbols is that they are derived from the name of the element in some other language. For instance, W comes from the German name for Tungsten, which is Wolfram.

Our program is intended to help a learner become familiar with the symbols for these eleven elements that have unexpected symbols.

Box 1 - The problem

The program should allow the user to ask for an entry from the list of the eleven elements with unexpected names. In response, the program should randomly pick an entry from the list. It should display the name of the element and invite the user to enter the corresponding symbol.

After the user enters their answer, the program should check the answer. If it is correct the program should congratulate the user, and then remove that element from the list (so once the user gets a symbol right, they don't get asked about that element again, unless they rerun the program, of course.)

Otherwise, if the answer is wrong the program should tell the user and inform them of the correct symbol for that element.

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. If they request another entry but the list is empty by this time the program should quit anyway.

A sample dialogue might run as follows.

What is the symbol for Sodium: K

Sorry that is wrong. The correct answer is Na

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

What is the symbol for Tin: Sn

Correct, well done!

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

What is the symbol for Silver: Au

Sorry that is wrong. The correct answer is Ag

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

What is the symbol for Antimony: Sb

Correct, well done!

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

What is the symbol for Tungsten: W

Correct, well done!

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

What is the symbol for Silver: Ag

Correct, well done!

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

What is the symbol for Sodium: Na

Correct, well done!

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

>>>

Box 2 - Keeping a notebook

In Part a (iv) we will be asking you to reflect briefly on your personal experiences as you tackled the modified flashcard problem. You will find this reflection much easier and more worthwhile if you keep some brief notes as you go along.

We suggest you record the following information:

How A brief description of how you went about the task.
Resources

Any documentation you consult (including course materials and any online sources) and which you found most useful.

Full references are not required: just note the source, and if you draw on the module materials record what part and section or activity you used.

Challenges Anything you find challenging about the task, and how you deal with it.
Lessons learned Anything you learn that you think would be useful if you faced a similar problem in the future.

a.

i.Write an algorithm for the following section from Box 1, reproduced here for convenience.

In response, the program should randomly pick an entry from the list. It should display the name of the element and invite the user to enter the corresponding symbol.

After the user enters their answer, the program should check the answer. If it is correct the program should congratulate the user, and then remove that element from the list (so once the user gets a symbol right, they don't get asked about that element again, unless they rerun the program of course.)

Otherwise, if the answer is wrong the program should tell the user and inform them of the correct symbol for that element.

Note that the remainder of the behaviour described in Box 1 is already taken care of in the supplied Python file and you do not need to do anything about it.

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.Say briefly how you will test the program. Only a short answer is required, and you do not need to give examples, only describe in a few lines what approach you will follow.

iii.Now you will implement your algorithm as Python code.

Translating the algorithm into Python code requires entries to be removed from the element list when appropriate. Use the following information about the Python del operation to remove entries from a Python dictionary.

Box - 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'}

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.

Important: Do not make change to any other parts of the program.

When you have made the required changes run the program to test it.

Copy your modified program, as text, into your Solution Document.

Please note:

The changes you make to the function show_flashcard() should be consistent with the algorithm you gave in part (i).

The chief purpose of this question is to let you show mastery of the TM112 problem solving approach and of the Python features that are introduced in the module and in Box 3 above.

If you consider there is a compelling reason why you need features not introduced 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.

iv.Also produce a short reflection looking back on your personal experience of solving the modified flashcard problem, following the framework given in Box 2 above.

Finally, include the final version of your completed Element_List_Flashcards_23D.py file in your TMA submission folder.

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

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions