Our users do not want to have to re-enter the price levels each time the app starts. Therefor, we need to save the price levels to a file on disk - called levelsFile - and populate the levelsList with the file's items when the app starts. Also, every time the user manipulates the values in levelsList, levelsFile needs to be updated accordingly. The easiest way is not to update the file, but to simply override it (create a new file) with the new values in levelsList (each time the user manipulates items in the list). Two new methods need to be created in the PriceChecker class. They are readLevelsFromFile() and writelevelsToFile(). And then the Main Code Section must also be updated to use these methods in the obiect.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please fill in the ellipsis(...) of how to read and write the levels(values) from a file for a price_checker:

#Method : Load levelsList using the data in levelsFile
def readLevelsFromFile(self):
try:
# Set levelsList to an empty list
self.levelsList = []
# Open the file
...
# Use a loop to read through the file line by line
...
# If the last two characters in the line is "\n", remove them
...
...
# Append the line to levelsList
...
# Close the file
...
except:
return

#Method: Write levelsList to levelsFile (override the existing file)
def writeLevelsToFile(self):
# Open the file in a way that will override the existing file (if it already exists)
...
# Use a loop to iterate over levelsList item by item
...
# Convert everything in the item to and then add \n to it - before writing to the file
...

# Close the file
...

# *************************************************************************************************
# Main Code Section
# *************************************************************************************************

# Create an object based on the PriceChecker class
checkerObj = PriceChecker()

#Load levelsList from the records in levelsFile
checkerObj.readLevelsFromFile()

# Display the levelsList and Menu; and then get user input for what actions to take
userInput = 99
while userInput != 0:
checkerObj.displayList()
userInput = checkerObj.displayMenu()
if (userInput == 1):
checkerObj.addLevel()
checkerObj,writeLevelsToFile() #Write levelsList to levelsFile
elif (userInput == 2):
checkerObj.removeLevel()
checkerObj.writeLevelsToFile() #Write levelsList to levelsFile
elif (userInput == 3):
checkerObj.removeAllLevels()
checkerObj.writeLevelsToFile() #Write levelsList to levelsFile

Our users do not want to have to re-enter the price levels each time the app starts.
Therefor, we need to save the price levels to a file on disk – called levelsFile - and populate the levelsList with
the file's items when the app starts.
Also, every time the user manipulates the values in levelsList, levelsFile needs to be updated accordingly. The
easiest way is not to update the file, but to simply override it (create a new file) with the new values in
levelsList (each time the user manipulates items in the list).
Two new methods need to be created in the PriceChecker class. They are readLevelsFromFile() and
writelevelsToFile(). And then the Main Code Section must also be updated to use these methods in the
obiect.
Transcribed Image Text:Our users do not want to have to re-enter the price levels each time the app starts. Therefor, we need to save the price levels to a file on disk – called levelsFile - and populate the levelsList with the file's items when the app starts. Also, every time the user manipulates the values in levelsList, levelsFile needs to be updated accordingly. The easiest way is not to update the file, but to simply override it (create a new file) with the new values in levelsList (each time the user manipulates items in the list). Two new methods need to be created in the PriceChecker class. They are readLevelsFromFile() and writelevelsToFile(). And then the Main Code Section must also be updated to use these methods in the obiect.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY