I have done this question, but I feel like for some lines, they were supposed to be changed would you be able to help me with that?     Consider the following function and attempted body. """ from typing import TextIO def allergy_checker(shopping_lists: TextIO, clean_shopping_lists: TextIO, allergies: list[str]) -> None: ''' shopping_lists is a file open for reading that has at least one food name on every non-blank line. Food names are separated by a space. Each line in shopping_lists ends with a newline character. clean_shopping_lists is a file open for writing. allergies is a list of one-word food names. Copy lines from shopping_lists to clean_shopping_lists. For each food name that is in the allergies list, replace it with 'REMOVED'. If a blank line in shopping_lists is reached, stop reading the file. ''' shopping_lists = open(shopping_lists) # Line 1 clean_shopping_lists = open(clean_shopping_lists, 'w') # Line 2 line = shopping_lists.readline() # Line 3 while line.strip(): # Line 4 line = shopping_lists.readline() # Line 5 for i in range(line): # Line 6 if line[i] in allergies: # Line 7 line[i] = 'REMOVED' # Line 8 clean_shopping_lists.write(f'{" ".join(line)}') # Line 9 line = shopping_lists.readline() # Line 10 """ There may be some bugs or errors in this code that prevent it from working properly. For each line, indicate: *OK* if the line is correct *REMOVE* if the line has to be removed *CHANGE* if the line has to be changed *you must also indicate what the line has to be changed to* # TODO: tell us what to do with each line Line 1 CHANGE shopping_lists is a file open for reading so this line should look like this: shopping_lists = open(shopping_lists, 'r') Line 2 OK Line 3 CHANGE Food names are seperated by lists so this line should look like this: line = shopping_lists.readline.split() n = int(lst[0]) k = int(lst[1]) Line 4 OK Line 5 REMOVE Line 6 OK Line 7 OK Line 8 OK Line 9 Ok Line 10 REMOVE """

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have done this question, but I feel like for some lines, they were supposed to be changed would you be able to help me with that?

 

 

Consider the following function and attempted body.
"""



from typing import TextIO

def allergy_checker(shopping_lists: TextIO,
clean_shopping_lists: TextIO, allergies: list[str]) -> None:
'''
shopping_lists is a file open for reading that has at least one food name on every
non-blank line. Food names are separated by a space.
Each line in shopping_lists ends with a newline character.
clean_shopping_lists is a file open for writing.
allergies is a list of one-word food names.

Copy lines from shopping_lists to clean_shopping_lists.
For each food name that is in the allergies list, replace it with 'REMOVED'.
If a blank line in shopping_lists is reached, stop reading the file.
'''
shopping_lists = open(shopping_lists) # Line 1
clean_shopping_lists = open(clean_shopping_lists, 'w') # Line 2
line = shopping_lists.readline() # Line 3
while line.strip(): # Line 4
line = shopping_lists.readline() # Line 5
for i in range(line): # Line 6
if line[i] in allergies: # Line 7
line[i] = 'REMOVED' # Line 8
clean_shopping_lists.write(f'{" ".join(line)}') # Line 9
line = shopping_lists.readline() # Line 10

"""
There may be some bugs or errors in this code that prevent it from working properly.

For each line, indicate:
*OK* if the line is correct
*REMOVE* if the line has to be removed
*CHANGE* if the line has to be changed
*you must also indicate what the line has to be changed to*


# TODO: tell us what to do with each line

Line 1
CHANGE
shopping_lists is a file open for reading so this line should look like this:
shopping_lists = open(shopping_lists, 'r')

Line 2
OK

Line 3
CHANGE
Food names are seperated by lists so this line should look like this:
line = shopping_lists.readline.split()
n = int(lst[0])
k = int(lst[1])

Line 4
OK

Line 5
REMOVE

Line 6
OK

Line 7
OK

Line 8
OK

Line 9
Ok

Line 10
REMOVE
"""

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education