Answered step by step
Verified Expert Solution
Link Copied!

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? )

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

=+5.14. Let f (x) be n2x or 2n -n2x or 0 according as 0 5x

Answered: 1 week ago

Question

1-4 How will MIS help my career?

Answered: 1 week ago