Add the purple code to your Main Code Section

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

Add the purple code to your Main Code Section (type it by hand if you get weird errors – especially the spaces - since PowerPoint might use Unicode characters that Python don’t recognize):

# *************************************************************************************************

#                                           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 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

Add the following method to your PriceChecker class and replace the ellipsis with the applicable code (type it by hand if you get weird errors – especially the spaces - since PowerPoint might use Unicode characters that Python don’t recognize):


    # Method: Load levelsList using the data in levelsFile 

    def readLevelsFromFile(self):

        try:

            # Set levelsList to an empty list 

            ...

            # 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

Add the following method to your PriceChecker class and replace the ellipsis with the applicable code (type it by hand if you get weird errors – especially the spaces - since PowerPoint might use Unicode characters that Python don’t recognize):



    # 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 a string and then add \n to it - before writing it to the file

            ...

        # Close the file

        ...

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