Question: What is the correct places the code must go? Write a program that uses lists to control a snack vending machine. The machine contains 10
What is the correct places the code must go?






Write a program that uses lists to control a snack vending machine. The machine contains 10 different kinds of snacks, labeled 'A' thru 'J'. Each snack cost $1.25. Requirements: The machine stocks 10 units of each snack type when the program starts. Customers enter the letter of the snack to buy, the quantity of snacks, and the money to pay for them. Your program shall display "Enjoy your snack!" only if the snack is in stock and the customer provided enough money to pay for it. Your program shall also display the corresponding amount of "change." The program shall keep track of the snacks sold. If the customer selects an out-of-stock snack, the program shall indicate so and end the transaction. If the customer does not provide enough money, the program shall display the appropriate messages and the customer shall not get the snack. The program shall runs until 'Z' is entered as the snack label; this signals the vending machine to "shut down." After the shut down, your program shall show the number of items sold of each kind of snack and the total sales. Assume the labels for the items are given in upper case letters. (Hint: use the ord() function to convert item labels into index values.) Here is a sample interaction with the Vending Machine: Vending machine ready... Enter letter A-J: A How many? 2 Enter money ($1.25): 2.5 Your change: 0.0 Enjoy your snack! Enter letter A-J: B How many? 11 Error: Cannot sell that many Enter letter A-J: A How many? 8 Enter money ($1.25): 20 Your change: 10.6 Enjoy your snack! Enter letter A-J: C How many? 1 Enter money ($1.25): 1.25 Your change: 0.0 Enjoy your snack! Enter letter A-J: Z Vending machine is now shutting down... Table of Items sold Item A: 10 Item B : 0 Item C : 1 Item D: 0 Item E: Item Fio Item G: 0 Item H: 0 Item I: Item J : Total sold: $ 13.75 Good Bye snacks = [10] * 10 # List to keep track of snacks sold print("Vending machine ready...") while option != 'Z': i = ord (option) - 65 if eval(input("How many? ")) quantity if if eval(input("Enter money ($1.25): ")) pay = if print("** Error: Item not sold") print("** Sorry, but", end='') print("that is not enough money.") print("** Try again.") else: change print("Your change:", change) print("Enjoy your snack!") else: print("Error: Cannot sell that many") else: print("Error: Cannot sell that many") else: else: print() print("Vending machine is now shutting down...") print("Table of Items sold") print("-- -") > for i in range (len(snacks)): print("Item", chr(i+65), ":", items Sold += print("- -") print("Total sold: $", print("Good Bye") quantity > 0 items Sold*1.25 snacks[i] >= quantity pay - (1.25 * quantity) items Sold = 0 snacks[i] -= quantity print("Error: Sold out") pay 0 10-snacks[i] i] print("Error: quantity must be more than 0")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
