Question: Assignment: Create a python file called VendingMachine.py . Download VendingMachine.txt from BB and copy it into VendingMachine.py . The file contains code defining the two
Assignment:
Create a python file called VendingMachine.py. Download VendingMachine.txt from BB and copy it into VendingMachine.py. The file contains code defining the two functions, getCoins and calcChange. It also defines a list, itemList, containing the description and price of each item.
Design and implement a program to simulate a vending machine. Submit both the flowchart and the resultant code. The functionality should be as follows:
Using the list of items (itemList), print out what items are available, their price and which button to press. Use button 0 for the first item; button 1 for the second item and button 2 for the third item.
Using getCoins, have the customer deposit a group of coins. (Note: getCoins returns the amount in pennies.)
Ask the customer to make a selection or enter 9 to get any remaining change.
As long as the remaining change is equal to or greater than 75 cents (the price of the cheapest selection) and the customer has not pressed 9:
Compare the change remaining to the price of the item as found in itemList. If the remaining change is equal to or greater than the price of the selected item, display Vending: and the description of the item, then subtract the price of the item from the remaining change. If the remaining change is less than the price of the selected item, display Not enough money. Try another item
Print change remaining
If the remaining change is equal to or greater than 75 cents, ask the customer to make another selection
Once the remaining change is less than 75 cents or the customer has selected 9, use calcChange to get a list of coins to refund and print out the number of coins of each coin type.
Be sure to thank the customer for their business !!
Example
Select from the following choices:
Select 0 for Candy price: 1.25
Select 1 for Water price: 0.75
Select 2 for Granola Bar price: 1.0
Enter list of coins : 25,25,25,25,10,10,10,5,1,25
total is $ 1.61
Enter selection or 9 to get change1
Vending Water
total remaining is $ 0.86
Enter selection or 9 to get change2
Not enough money. Try another item.
total remaining is $ 0.86
Enter selection or 9 to get change9
Dispensing change:
0 Dollars
3 Quarters
1 Dimes
0 Niclels
1 Pennies
Thank you for your patronage !!
HERE IS THE VendingMachine.txt WE MUST USE:
def getCoins():
total=0
coinList=eval(input("Enter list of coins : "))
for coin in coinList:
total += coin
return total
def calcChange(amount):
changeList=[0,0,0,0,0]
changeList[0]=amount//100
amount=amount%100
changeList[1] = amount // 25
amount = amount % 25
changeList[2] = amount // 10
amount = amount % 10
changeList[3] = amount // 5
amount = amount % 5
changeList[4] = amount
return changeList
def main():
itemList = [["Candy", 125], ["Water", 75], ["Granola Bar", 100]]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
