Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are required to design and implement two relatedRequirements of admin . py The requirements are: 1 . The first thing the program should do

You are required to design and implement two relatedRequirements of admin.py
The requirements are:
1. The first thing the program should do is try to open a file named data.txt in read mode, then
load the data from the file into a variable named data and then close the file. The data in the file should be in JSON format, so you will need to use the load() function from the
json module to read the data into your program.
If any exceptions occur (e.g. due to the file not existing, or it not containing valid JSON data), then
simply set the data variable to be an empty list. This will occur the first time the program is run, since
the data file will not exist yet. This ensures that you are always left with a list named data.
This is the only time that the program should need to read anything from the file. From this point the
program uses the data variable, which is written to the file whenever anything is added or deleted.
2. The program should then print a welcome message and enter an endless loop which starts by
printing a list of options: Choose [a]dd,[l]ist,[s]earch,[v]iew,[d]elete or [q]uit. and then
prompts the user to enter their choice. Once a choice has been entered, use an if/elif
statement to handle each of the different choices (detailed in the following requirements).
3. If the user enters a(add), prompt them to enter a question, then prompt them to enter as many
answers as desired, and finally prompt them to enter the difficulty of the question, which must be
an integer between 1 and 3. Place the details into a new dictionary with the structure shown on
Page 3, and append the dictionary to the data list. Finally, write the entire data list to the text
file in JSON format to save the data.
Use your input_something() function (detailed below) when prompting for question and
answers, to ensure that they are re-prompted until they enter something other than whitespace.
How you handle prompting the user to enter multiple answers is up to you, as long as you ensure that
they enter at least one answer. You may want to store the answers in lowercase, to make it easier to
match the users answer to them in the GUI program.
Use your input_int() function (detailed below) when prompting for an index number, to ensure
that the user is re-prompted until they enter an appropriate integer.
Be sure to include the correct and incorrect keys in the dictionary, both set to 0.
Once the dictionary for the new question has been appended to the data list, call your
save_data() function (detailed below) to write the data to the text file in JSON format.
4. If the user enters l(list), print a list of all the questions (just the question text) in the data list,
preceded by their index number plus 1(so that the list starts from 1 rather than 0).
If the data list is empty, show a No questions saved message instead.
Use a for loop to iterate through the items in the data list. Remember: each item is a dictionary.
You can use the enumerate() function to ensure that you have access to variables containing the
index number and dictionary of each item as you loop through them
5. If the user enters s(search), prompt them for a search term and then list the questions that
contain the search term in the question text. Display search results in the same way that you
display questions when listing them, including the index number plus 1.
If the data list is empty, show a No questions saved message instead of prompting for a search term.
Use your input_something() function (detailed below) when prompting for a search term, to
ensure that the user is re-prompted until they enter something other than whitespace.
The code to search will be similar to the code used to list, but this time the loop body needs an if
statement to only print questions that contain the search term (use the in operator
Ensure that the searching is not case-sensitive, e.g.programming should find Programming.
If the search term is not found in any of the questions, show a No results found message.
6. If the user enters v(view), prompt them for an index number and then print details of the
corresponding question in full. This should include the question text, answers, difficulty, and how
many times the question has been answered correctly and incorrectly.
If the data list is empty, show a No questions saved message instead of prompting for index number.Use your input_int() function (detailed below) when prompting for an index number, to ensure
that the user is re-prompted until they enter an appropriate integer.
Remember: Index numbers shown to/entered by users start from 1, but the data list starts from 0.
Print the list of answers in a pleasing way (without []), rather than simply printing the entire list. e.g.
Print Easy/Medium/Hard alongside the difficulty for 1/2/3,

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

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

4. Compute and interpret percentile ranks and z scores.

Answered: 1 week ago

Question

Describe several uses for a position description.

Answered: 1 week ago