Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def add_item(user_input): items. append (user_input) def terminate( ): # if is_exit_confirmed( ): print('>>> Bye!') sys. exit() else: print(' >>> What can I do for you?
def add_item(user_input): items. append (user_input) def terminate( ): \# if is_exit_confirmed( ): print('>>> Bye!') sys. exit() else: print(' >>> What can I do for you? ) def read_command( ): name = input () return name def print_greeting(): print(' >> Hello, my name is Monty') print(' >>> What can I do for you? ) def is_exit_confirmed( ): print (>> Are you sure? y) def mark_item_as_done(user_input): index_as_string = user_input [5:] get_item_for_index(index_as_string) [1] = True def execute_command(command): if command == : return elif command == 'exit': terminate() elif command == 'list': print_items() \#print (' >>> What can I do for you? ) \#return elif command. startswith( 'add '): add_item(command) \#print (' >>> What can I do for you? ) elif command.startswith( done "): mark_item_as_done(command) else: raise Exception( 'Command not recognized ') \#print (' >> OOPS! Unknown command') lef main(): print_greeting() while True: try: command = read_command () execute_command (command) except Exception as e: print('>>> SORRY, I could not perform that command. Problem:', e) - Add a done command so that the user can mark a task as done. e.g., marks the task at index 2 as done. - Show appropriate error messages if the user gives an invalid index for the done command - Optionally, implement an undone (or unmark) command to change the status of a task back to not done. A sample output is given below. > Hello, my name is Monty >>> What can I do for you? add borrow book >> What can I do for you? add read book > What can I do for you? add return book >>> What can I do for you? list >>> List of items: [ ] 1. borrow book [ ] 2. read book [ ] 3. return book > What can I do for you? done 1 >> What can I do for you? list >> List of items: [X] 1. borrow book [ ] 2. read book [ ] 3. return book > What can I do for you? done abc >>> SORRY, I could not perform that command. Problem: abc is not a number >>> What can I do for you? done 5 >>> SORRY, I could not perform that command. Problem: No item at index 5 >>> What can I do for you? done >>> SORRY, I could not perform that command. Problem: Index must be greater than >>> What can I do for you? garbage >>> SORRY, I could not perform that command. Problem: Command not recognized > What can I do for you? exit >>> Are you sure? y y
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