Question: Enhance the Monty Level 3 code to improve the functionality as per the sample output given below. >>> Hello, my name is Monty >>> What

Enhance the Monty Level 3 code to improve the functionality as per the sample output given below.

>>> Hello, my name is Monty >>> What can I do for you? list >>> Nothing to list >>> What can I do for you? add read book >>> What can I do for you? list >>> List of items: 1. read book >>> What can I do for you? add return book >>> What can I do for you? list >>> List of items: 1. read book 2. return book >>> What can I do for you? exit >>> Are you sure? y/n y >>> Bye!

You can use the list slicing syntax to extract a portion of a string.

s = 'abcdefgh' print(s[2:]) print(s[:5]) 
cdefgh abcde 

The above technique can be used to extract the item description from an add command.

Partial Solution:

import sys

items = []

def print_items(): if len(items) == 0: print('>>> Nothing to list') else: for i, item in enumerate(items): # ...

def add_item(user_input): # ...

def terminate(): # ...

# ...

def execute_command(command): if command == '': return elif command == 'exit': terminate() elif command == 'list': print_items() elif command.startswith('add '): add_item(command) else: print('>>> OOPS! Unknown command')

def main(): print_greeting() while True: command = read_command() execute_command(command)

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!