Question
Please do in Python 3 IDE( if you need more information tell me) Using the coffee program in-class lecture. Modify each of the 5 functions
Please do in Python 3 IDE( if you need more information tell me)
Using the coffee program in-class lecture. Modify each of the 5 functions to make it into a module. Write a program to import all five of the modules you have created. In this program you will create a menu so that the user can choose what the user wants to do. For example user can choose to add a new coffee record, delete a coffee record, modify a coffee record, search a coffee record or show coffee records. You must use the same file names for the functions that were given to you when you save a modules. For example, add_coffee_record.py, delete_coffee_record.py, modify_coffee_records.py, search_coffee_records.py, and show_coffee_records.py. Upload only the menu program you have created.
Notes: Files Open text files using the open, read/write, close outfile = open(test.txt, w) outfile.write(Score) outfile.close() Opens a text using the with statement. Using the with statement will automatically closes the file With open(test.txt,w) as outfile: outfile.write(Score) #need to indent
More List stuff List Methods for modifying a list append(item) append item to end of list. insert(index, item) insert item into specified index remove(item) removes first item in the list that is equal to the specified item. ValueError raised if not found index(item) returns the index of the first occurrence of specified item. ValueError raised if not found. pop(index) if no index argument is specified, this method gets the last item from the list and removes it. Otherwise, this method gets the item at the specified index and removes it. The pop() method inventory = ["staff", "hat", "robe", "bread"] item = inventory.pop() # item = "bread" since no arguments remove from the end of list # inventory = ["staff", "hat", "robe"] item = inventory.pop(1) # item = "hat" remove at index 1 # inventory = ["staff", "robe"] The index() and pop() methods inventory = ["staff", "hat", "robe", "bread"] i = inventory.index("hat") # 1 inventory.pop(i) # ["staff", "robe", "bread"] try and except for trapping errors. The hierarchy for five common errors Exception OSError FileExistsError FileNotFoundError ValueError How to handle a ValueError exception try: number = int(input("Enter an integer: ")) print("You entered a valid integer of " + str(number) + ".") except ValueError: print("You entered an invalid integer. Please try again.") print("Thanks!") output with error: Enter an integer: five You entered an invalid integer. Please try again. Thanks! Code that handles multiple exceptions (example used with files) filename = input("Enter filename: ") movies = [] try: with open(filename) as file: for line in file: line = line.replace(" ", "") movies.append(line) except FileNotFoundError: print("Could not find the file named " + filename) except OSError: print("File found - error reading file") except Exception: print("An unexpected error occurred")
# This program displays the records in the # coffee.txt file. def show ) # Open the coffee.txt file. coffee file -open (coffee.txt'r # Read the first record's description field. descr = coffeefile. readline() - # Read the rest f the file. while descr '= '': # Read the quantity field. qtyfloat (coffee file.readline )) # Strip the from the description. descr- descr.rstrip('n' # Display the record. print('Description:', descr) print('Quantity:', qty) # Read the next description. descr = coffeefile. readline() - # C1 se the file. coffee_file.close ) # This program displays the records in the # coffee.txt file. def show ) # Open the coffee.txt file. coffee file -open (coffee.txt'r # Read the first record's description field. descr = coffeefile. readline() - # Read the rest f the file. while descr '= '': # Read the quantity field. qtyfloat (coffee file.readline )) # Strip the from the description. descr- descr.rstrip('n' # Display the record. print('Description:', descr) print('Quantity:', qty) # Read the next description. descr = coffeefile. readline() - # C1 se the file. coffee_file.close )Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started