Answered step by step
Verified Expert Solution
Question
1 Approved Answer
mport sys tems=[] ef add_item(user_input): items.append([user_input, user_input]) ef terminate(): # if is_exit_confirmed(): print(' >>> Bye!') sys.exit() else: print('>>> What can I do for you? )
mport sys tems=[] ef add_item(user_input): items.append([user_input, user_input]) ef terminate(): \# if is_exit_confirmed(): print(' >>> Bye!') sys.exit() else: print('>>> What can I do for you? ) ef read_command(): name = input () return name Level 7 Save Tasks to Disk Enhance the Monty Level 6 code in the following ways: - Monty saves tasks into a csv file, and loads data from the same file at the start. - Add a delete command that can delete a task at a specific index. A sample output is given below. Note the following: - Monty is able to show at the very start the three tasks loaded from the file. - When item 2 is deleted, the item previously at index 3 moves to position 2. Q) here are some tips: - The filename can be specified in the code. e.g., 1 DATA_FILE = 'monty7.csv' - The following statement will create an empty data.csv file if the file doesn't exist, but will keep the file as it is if it already exists (it simply opens the file in append mode -- which creates the file it if it doesn't exist -- and close it right after). 1 open( 'data.csv', 'a').close() - The format of the file is up to you. Here is an example: 1 borrow book, done 2 read book, pending - The program can load the tasks from the file at the beginning. It can save the data after each command. For example, as follows: D Partial solution Here is the code for loading data from the file. def load_data(filename): data_file = open(filename) deliveries_reader = csv. . reader if not row: continue add_item_from_ def add_item_from_csv_line(values): status = True if values [1]== 'done' else False items.append([values[0], status ] ) \# items is a global variable Note that status = True if values [1]== 'done' else False is a shortcut syntax. It is equivalent to the code below: 1 if values [1]== 'done' : st mport sys tems=[] ef add_item(user_input): items.append([user_input, user_input]) ef terminate(): \# if is_exit_confirmed(): print(' >>> Bye!') sys.exit() else: print('>>> What can I do for you? ) ef read_command(): name = input () return name Level 7 Save Tasks to Disk Enhance the Monty Level 6 code in the following ways: - Monty saves tasks into a csv file, and loads data from the same file at the start. - Add a delete command that can delete a task at a specific index. A sample output is given below. Note the following: - Monty is able to show at the very start the three tasks loaded from the file. - When item 2 is deleted, the item previously at index 3 moves to position 2. Q) here are some tips: - The filename can be specified in the code. e.g., 1 DATA_FILE = 'monty7.csv' - The following statement will create an empty data.csv file if the file doesn't exist, but will keep the file as it is if it already exists (it simply opens the file in append mode -- which creates the file it if it doesn't exist -- and close it right after). 1 open( 'data.csv', 'a').close() - The format of the file is up to you. Here is an example: 1 borrow book, done 2 read book, pending - The program can load the tasks from the file at the beginning. It can save the data after each command. For example, as follows: D Partial solution Here is the code for loading data from the file. def load_data(filename): data_file = open(filename) deliveries_reader = csv. . reader if not row: continue add_item_from_ def add_item_from_csv_line(values): status = True if values [1]== 'done' else False items.append([values[0], status ] ) \# items is a global variable Note that status = True if values [1]== 'done' else False is a shortcut syntax. It is equivalent to the code below: 1 if values [1]== 'done' : st
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