Add the purple code to your Main Code Section
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
...
Step by step
Solved in 3 steps