Page 218 -
P. 218
modular programming
Code Magnets
Now that you know how to format the records in the
transactions.txt file, it is time to write the rest of the coffee
bar POS program. Complete the code below by arranging the code
magnets in the correct place:
The “a" means you are always
def save_transaction(price, credit_card, description): going to APPEND records
to the end of the file.
file = open("transactions.txt", "a")
file.write("%s%07d%s\n" % (credit_card, price * 100, description))
file.close()
This is the format string you just created.
items = ["DONUT", "LATTE", "FILTER", "MUFFIN"]
prices = [1.50, 2.0, 1.80, 1.20]
The loop will keep running while
running = True
the “running” variable has the
while running: value True. T o end the loop, set
“running” to False.
option = 1
for choice in items:
option = option + 1
print(str(option) + ". Quit")
if choice == option:
else:
save_transaction(prices[choice - 1], credit_card, )
credit_card = input("Credit card number: ") items[choice - 1] running = False
print(str(option) + ". " + choice) choice=int(input("Choose an option: "))
you are here 4 183