hope someone can help. im trying to create a virtual vending machine. ive got so far with my code but stuck on a few things. i need help in creating a code in this section.
count = 0
TotalCredit = 0
coinNum = int (input("How many coins would you like to enter: "))
while count in range (coinNum):
coin = float (input ("Coins accepted 0.10 0.20 0.50 1.00: £ "))
TotalCredit = TotalCredit + coin
count = count + 1
so if coins entered are anything other than 0.10 0.20 0.50 1.00 it prints a message "Invalid coin entered please try again" and loops back to start.
i also need a while loop so if there is not enough credit entered it prints "insufficient funds please add more credit" and goes back to allow you to add credit. I know the minimum amount of credit is 0.59 so i have and idea the the loop is something like 'while TotalCredit <0.59 but not sure how to send user back to add more. ive listed code below so you can see how far ive gone. im only 15 and just learning coding so please as much help as possible would be much appreciated.
def vendingMachine():
count = 0
TotalCredit = 0
coinNum = int (input("How many coins would you like to enter: "))
while count in range (coinNum):
coin = float (input ("Coins accepted 0.10 0.20 0.50 1.00: £ "))
TotalCredit = TotalCredit + coin
count = count + 1
print ("You have £",round(TotalCredit,2),"credit " )
print ("")
print ("Choose your item:")
print ("")
print ("1.Coco-Cola")
print ("2.Walkers Cheese & Onion")
print ("3.Lucozade")
print ("4.Wosits")
print ("5.Water")
print ("")
FinalCredit = TotalCredit
round (FinalCredit, 2)
item = int (input ("Enter the number for your item: "))
print ("")
while item <1 or item >5:
print ("This item is not available.")
item = int (input ("Enter the number for your item: "))
if item == 1:
FinalCredit = TotalCredit - 0.59
print ("You now have a Coca-Cola can, costing £0.59.")
print ("You have",round(FinalCredit,2),"credit remaning.")
elif item == 2:
FinalCredit = TotalCredit - 0.69
print ("You now have a Walkers crisp packet, costing £0.69.")
print ("You have", round(FinalCredit,2),"credit remaning.")
elif item == 3:
FinalCredit = TotalCredit - 0.99
print ("You now have a Lucozade drink, costing £0.99.")
print ("You have" ,round(FinalCredit,2),"credit remaning.")
elif item == 4:
FinalCredit = TotalCredit - 0.59
print ("You now have a Wosits crisp packet, costing £0.59.")
print ("You have",round(FinalCredit,2),"credit remaning.")
elif item == 5:
FinalCredit = TotalCredit - 0.79
print ("You now have a bottle of water, costing £0.79.")
print ("You have",round(FinalCredit,2),"credit remaning.")
else:
print ("This not an option.")
print ("")
print ("The rest of your money, £(0), has been
outputted.".format(round(FinalCredit,2)))
vendingMachine ()