Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in python please ! Your assignment is to create the following functions. The functionality for each function is described below. You must follow the specifications
in python please !
Your assignment is to create the following functions. The functionality for each function is described below. You must follow the specifications exactly, but may choose your own method for solving the problem described for each. Once you have completed a function you should run the unittest for that function and have it pass all tests. Fix any errors, warnings, and/or failures. Because of the user input and output, not all functions are easily tested with unit tests. Be sure to test these functions by running your program and observing the correct behavior. The function createIndex does not receive any parameters. It must return an empty dictionary for the index. createIndex (){} recordBook The function recordBook receives three parameters, the index dictionary, the ISBN of a book, and the title of a book. Both the ISBN and title are strings. It must assign the title to the ISBN in the index. It does not return anything. However, the dictionary will be modified as a result of this function's work. recordBook ( index, "978-0439023528", "The Hunger Games" index should now contain the book findBook The function findBook receives two parameters, the index dictionary and the ISBN of a book. The ISBN is a string. The function returns the title of the book with the matching ISBN, if it exists. If the ISBN is not in the dictionary, then it returns the empty string. findBook ( index, "978-0439023528" ) "The Hunger Games " findBook ( index, "888-8888888888") "n The function 1 istBooks receives one parameter, the index dictionary. The function returns a list of strings. Each string in the list is a line that shows a sequence number, the ISBN and the title of a book. See the examples for the format of the lines. If there are no books in the index, this function returns an empty list. listBooks ( empty_index ) [ ] listBooks ( index ) [ "1) 978-0439023528: The Hunger Games", "2) 978-0439708180: Harry Potter and the Sorcerer's Stone" ] IoxmatManu The function formatMenu does not receive any paranteters. It must return a list of strings that contains the lines of the menu. formatMenu ( ) [ 'What would you like to do?', '[r] 'Record a Book', '[f] Find a Book', '[1] List all Books', formatMenuPrompt The function formatMenuPrompt does not receive any parameters. It must return a string that contains the prompt to ask the user which menu option they would like to select. formatMenuprompt() 'Enter an option: getUserChoice The function getUserchoice receives one parameter, a string that contains a prompt for input. It must return a string that contains the text input by the user, with any leanding and trailing whitespace removed. If the user gives an empty string, prompt them again, until they give a non-empty string. Note that this function interacts with the user, so there will be output to the screen and input from the keyboard when it is called. getUserchoice( "Hello? " ) 'some text' getUserchoice ( "Choose" ) 'othertext' getISBN The function getISBN does not receive any parameters. It must prompt the user for an ISBN, and return the ISBN input by the user. The user's response must not have any leading or trailing whitespace. It must repeatedly ask the user for an ISBN, until the user gives a non-empty response. Note, you should probably call getUserchoice as part of this function. getISBN ( ) ' 9780439708180 getISBN ( ) 'user-typed-this' getTitle The function getTitle does not receive any parameters. It must prompt the user for a book title, and return the title input by the user. The user's response must not have any leading or trailing whitespace. It must repeatedly ask the user The function getTitle does not receive any parameters. It must prompt the user for a book title, and return the title input by the user. The user's response must not have any leading or trailing whitespace. It must repeatedly ask the user for a title, until the user gives a non-empty response. Note, you should probably call getUserchoice as part of this function. getTitle( ) "Harry Potter and the Sorcerer's Stone" getritle( ) 'user-typed-this too. Weirdl' recordBookAction The function recordBookAction receives the index dictionary as a parameter. It must ask the user for the ISBN and title of a book, and add it to the dictionary. This function does not return anything. However, it has the side effect of adding an entry to the dictionary. It also interacts with the user through input and output. Note you should be using some of the above functions to complete this function. recordBookAction ( index ) the index dictionary should be modified The function f indBookAction receives the index dictionary as a parameter. It must ask the user for the ISBN of a book. If the book exists in the dictionary, it will display (print) the book title. If the book does not exist in the dictionary, it will print a message to let them know. The function does not return anything and should not change the index. findBookaction ( index ) the index dictionary should not be modified IistBooksAction The function listBooksAction receives the index dictionary as a parameter. It will display all of the books in the dictionary in the format shown in the examples. If there are no books in the dictionary, it must display a message to inform the user. The function does not return anything. The function must not change the dictionary. listBooksAction ( index ) the index dictionary should not be modified quitAction The function quitaction receives the index dictionary as a parameter. This function will display a message to the user indicating the end of the program. It will then terminate the program using sys.exit ( 0 ). Be sure to do the correct import statement. This function does not return anything. applyaction The function applyAction receives the index dictionary and a choice string as parameters. This function will call the appropriate action function based on the choice string. If the choice string does not match any accepted choices, it will display a message to the user. This function does not return anything. The dictionary may be changed as a result of the chosen action. applyAction ( index, " r " ) the dictionary will have a new book added. applyAction ( index, " f" ") the user will select a book to display. applyAction ( index, " 1 " ) the contents of the dictionary will be displayed. applyaction ( index, " q ") the program will terminate. applyAction ( index, "bad-choice") the user will receive a message. main The function main receives no parameters, and returns nothing. This function ties everything together. Creating an index, repeatedly asking the user their choice and taking action. main ( ) the program runs. dictionary may be changed as a result of the chosen action. applyAction ( index, " r" " the dictionary will have a new book added. applyAction ( index, "f") the user will select a book to display. applyAction ( index, " 1 " ) the contents of the dictionary will be displayed. applyAction ( index, "q") the program will terminate. applyAction( index, "bad-choice" ) the user will receive a message. in The.function main receives no parameters, and returns nothing. This function ties everything together. Creating an index, repeatedly asking the user their thoice and taking action. nain () the program runs. Finishing Up Lastly add this snippet at the bottom of your file which will execute your main( ) function when you run isbn_index. py but will allow it to be imported into the unittest files without executing the main function. if main()mame== main 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