Page 219 -
P. 219
new pos program
Code Magnets Solution
Now that we know how to format the records in the
transactions.txt file, it is time to write the rest of the coffee
bar POS program. You were to complete the code below by arranging
the code magnets:
def save_transaction(price, credit_card, description):
file = open("transactions.txt", "a")
file.write("%s%07d%s\n" % (credit_card, price * 100, description))
file.close()
This is the array of menu options.
items = ["DONUT", "LATTE", "FILTER", "MUFFIN"]
prices = [1.50, 2.0, 1.80, 1.20] This is the matching array of menu prices.
running = True
while running: This code displays the
option = 1 program's menu.
for choice in items:
print(str(option) + ". " + choice)
option = option + 1
print(str(option) + ". Quit")
The user enters a menu
choice = int(input("Choose an option: ")) option number to make a sale.
if choice == option:
This will be True if the user selects the LAST
option on the menu, which is “Quit.”
running = False
else:
credit_card = input("Credit card number: ")
save_transaction(prices[choice - 1], credit_card, )
items[choice - 1]
184 Chapter 6