Question

In the original flashcard problem, a user can ask the program to show an entry picked...

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

There are now two glossaries: the ‘easy’ and the ‘hard’.

The program should allow the user to ask for either an ‘easy’ or a ‘hard’ glossary entry. If the user chooses to see an ‘easy’ entry, the program picks an entry at random from the easy glossary and shows the entry. After the user presses return, the program should show the definition for that entry.

If the user chooses to see a ‘hard’ entry, the program picks an entry at random from the hard glossary and shows the entry. After the user presses return, the program should show the definition for that entry.

The user should be able to repeatedly ask for an easy or a hard entry or choose an option to quit the program.

A sample dialogue might run as follows. Changes from the original flashcard program are indicated by underlining. word3 is from the ‘easy’ glossary, word6 from the ‘hard’ glossary.

Enter e to show an easy flashcard, h to show a hard one, and q to quit: e Define: word3 Press return to see the definition definition3 Enter e to show an easy flashcard, h to show a hard one, and q to quit: h Define: word6 Press return to see the definition definition6 Enter e to show an easy flashcard, h to show a hard one, and 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 subproblem of showing a random entry from either the easy or the hard glossary and, after the user enters return, showing the definition. The algorithm should select which glossary to use depending on the user's input.

  • a.

    • i.Begin by writing an algorithm for the subproblem, show definition, described in the middle paragraph of Box 1 above, and repeated here for convenience:

      The program should allow the user to ask for either an easy or a hard glossary. If the user chooses to see an easy entry, the program picks an entry at random from the easy glossary and shows the entry. After the user presses return, the program should show the definition for that entry.

      If the user chooses to see a hard entry, the program picks an entry at random from the hard glossary and shows the entry. After the user presses return, the program should show the definition for that entry.

      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. Your algorithm will need to cater for the two variables of the user asking for either an easy or a hard entry.

      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.

      We have provided a starter script which is included in the download for this TMA as Q2.py. This script is a modified version of the first complete version of the flashcard program as developed in Block 3 Part 2. The only change we have made to the code is that there are now two glossaries set up, the easy and the hard. The code that does this is near the start of the program.

      Begin by saving a copy of the provided program as Q2_OUCU.py (where OUCU is your OU computer username, e.g. abc123).

      Modify the function show_flashcard() so it translates into Python the steps of the algorithm you wrote in Part (i). You can assume the user's choice is stored in the variable user_input and is either 'e' or 'h' for easy or hard respectively.

      Make sure you write a suitable docstring for the function.

      Copy your modified show_flashcard() function and paste it into your Solution Document.

    • iii.When you have modified the show_flash card() function, test it as follows.

      Run the program and, when asked to make a choice, immediately enter q so the program quits.

      Although the program has quit, the function is still loaded into memory and can be called from the shell. To test it, first set the value of user_input to 'e'

      >>> user_input = 'e'

      Now call the function

      >>> show_flashcard()

      If the function is correct, this should display one of the ‘easy’ words: word1, word2 or word3, followed by Press return to see the definition.

      Repeat this process but this time set the value of user_input to 'h' and check that now the word displays one of the 'hard' words: word4, word5 or word6.

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

      Copy and paste two example tests into your Solution Document. The first test should show the result of user_input being set to 'e', the function being called, and the user pressing return. The second test should show the result of user_input being set to 'h', the function being called, and the user pressing return.

      Alternatively, if you were unable to get the function working correctly, you should still paste in example tests 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 a choice between entering 'e' for an easy entry, 'h' for a hard entry, or 'q' to quit.

      If the user enters either ‘e’ or ‘h’, the show_flashcard() function should be called. The function will then show a random entry from either the easy or hard glossary, depending on which of the two the user chose, which will have resulted in user_input being set to the corresponding value.

      If the user enters ‘q’, the program should quit as before.

      If the user enters anything else, the program should print a message reminding them what the possible options are.

      Once you have made the changes, run the whole program. Copy a test dialogue into your Solution Document to show the user first choosing to see an 'easy' entry, then a 'hard' one, then entering an invalid option, and finally entering 'q' to quit the program.

      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 Q2_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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the complete program:

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.   
"""
glossary = {}
if user_input == 'e':
glossary = easy_glossary
elif user_input == 'h':
glossary = hard_glossary
else:
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

easy_glossary = {'word1':'definition1',
'word2':'definition2',
'word3':'definition3'}

hard_glossary = {'word4':'definition4',
'word5':'definition5',
'word6':'definition6'}

# The interactive loop
exit = False
user_input = 'e'
while not exit:
user_input = (input("Enter 'e' for an easy entry, 'h' for a hard entry, or 'q' to quit: "))
if user_input == 'q':
print("Thanks for using the program!")
exit = True
elif user_input == 'e' or user_input == 'h':
show_flashcard()
else:
print('You need to enter either e, h or q')

The program as image file as code indentation is important in python, please maintain that.

1 from random import * 3 - def show_flashcard : Show the user a random key and ask them to define it. Show the definition whe

sample output:

input Enter e for an easy entry, h for a hard entry, or q to quit: e Define: wordi Press return to see the definition d

Add a comment
Know the answer?
Add Answer to:
In the original flashcard problem, a user can ask the program to show an entry picked...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • Write a program that defines a Print Job structure as follows: 1) An integer job Id...

    Write a program that defines a Print Job structure as follows: 1) An integer job Id 2) A string user name (maximum 25 characters) 3) An integer tray (tray will hold the tray number 1 for 8 1/2 by 11 paper, number 2 for 8 1/2 by 11 paper, and number 3 for 8 1/2 by 14 paper) 4) An integer for paper size (this will hold a percentage: 100% is normal, 150% is 1.5 times the size) 5) A...

  • Write a Python program that asks the user to type in their three quiz scores (scores...

    Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...

  • Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is g...

    Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is given to you in file Seattle_911_Incidents.csv which contains 500 records (a subset of the approximately 53,000 911 calls made in Seattle in the years 2015-2017). This dataset is the Police responses to 9-1-1 calls within the city during the 2015-2017 years. You can get the full data set from http://data.seattle.gov. The data consists of 500 rows, where each row is...

  • Can you help me to create this program, please? Prompt the user for the user for...

    Can you help me to create this program, please? Prompt the user for the user for a number of degrees in Fahrenheit as an int. That number should be passed to a function named ffocREFO. This function will do the necessary calculation to convert the passed temperature to degrees Celsius as a double. The function MUST have a void return type and have the following prototype: void ffccREF(double& celsius, int Faren); In your main, display both the entered temperature and...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

  • Objectives By the end of this program, the student will have demonstrated the ability to Write...

    Objectives By the end of this program, the student will have demonstrated the ability to Write static methods Use methods in a different class Write a sentinel-controlled loop Write nested if/else statements Manipulate Strings by character position StringUtils You are to complete the class StringUtils, which is in the attached zip file. Add the following public static methods: copy Write a method String copy(String currentString, int startPosition, int onePastLastPosition). This method returns a substring of currentString, including startPosition, but ending...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit...

    Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT