Answered step by step
Verified Expert Solution
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 adminpy The requirements are: The first thing the program should do is try to open a file named datatxt 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 eg 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. The program should then print a welcome message and enter an endless loop which starts by printing a list of options: Choose addlistsearchviewdelete or quit and then prompts the user to enter their choice. Once a choice has been entered, use an ifelif statement to handle each of the different choices detailed in the following requirements If the user enters aadd 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 and Place the details into a new dictionary with the structure shown on Page 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 inputsomething function detailed below when prompting for question and answers, to ensure that they are reprompted 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 inputint function detailed below when prompting for an index number, to ensure that the user is reprompted until they enter an appropriate integer. Be sure to include the correct and incorrect keys in the dictionary, both set to Once the dictionary for the new question has been appended to the data list, call your savedata function detailed below to write the data to the text file in JSON format. If the user enters llist print a list of all the questions just the question text in the data list, preceded by their index number plus so that the list starts from rather than 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 If the user enters ssearch 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 If the data list is empty, show a No questions saved message instead of prompting for a search term. Use your inputsomething function detailed below when prompting for a search term, to ensure that the user is reprompted 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 casesensitive egprogramming should find Programming If the search term is not found in any of the questions, show a No results found message. If the user enters vview 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 inputint function detailed below when prompting for an index number, to ensure that the user is reprompted until they enter an appropriate integer. Remember: Index numbers shown toentered by users start from but the data list starts from Print the list of answers in a pleasing way without rather than simply printing the entire list. eg Print EasyMediumHard alongside the difficulty for
You are required to design and implement two relatedRequirements of adminpy
The requirements are:
The first thing the program should do is try to open a file named datatxt 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 eg 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.
The program should then print a welcome message and enter an endless loop which starts by
printing a list of options: Choose addlistsearchviewdelete or quit and then
prompts the user to enter their choice. Once a choice has been entered, use an ifelif
statement to handle each of the different choices detailed in the following requirements
If the user enters aadd 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 and Place the details into a new dictionary with the structure shown on
Page 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 inputsomething function detailed below when prompting for question and
answers, to ensure that they are reprompted 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 inputint function detailed below when prompting for an index number, to ensure
that the user is reprompted until they enter an appropriate integer.
Be sure to include the correct and incorrect keys in the dictionary, both set to
Once the dictionary for the new question has been appended to the data list, call your
savedata function detailed below to write the data to the text file in JSON format.
If the user enters llist print a list of all the questions just the question text in the data list,
preceded by their index number plus so that the list starts from rather than
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
If the user enters ssearch 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
If the data list is empty, show a No questions saved message instead of prompting for a search term.
Use your inputsomething function detailed below when prompting for a search term, to
ensure that the user is reprompted 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 casesensitive egprogramming should find Programming
If the search term is not found in any of the questions, show a No results found message.
If the user enters vview 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 inputint function detailed below when prompting for an index number, to ensure
that the user is reprompted until they enter an appropriate integer.
Remember: Index numbers shown toentered by users start from but the data list starts from
Print the list of answers in a pleasing way without rather than simply printing the entire list. eg
Print EasyMediumHard alongside the difficulty for
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started