I need to code a vending machine, that only accepts certain coins
"It will allow you to input 1p, 2p, 5p, 10p, 20p, 50p and £1.00 but it will REJECT a £2.00 coin"
I have a list, with float values inside:
coins = ["0.01","0.02","0.05","0.10","0.20","0.50","1"]
These are the coins, that I am wanting the user to enter into
coin = float(input())
And after this I have
def balance():
coin = float(input("Please enter your coins."))
if coin not in coins:
print("Incorrect coin amount! Please remember we don't accept 2 pound coins!")
else:
print("Correct coin amount. The coins have been added to your balance")
fb = fb + coin
I couldn't get this to work, as it would just print "Incorrect coin amount! Please remember we don't accept 2 pound coins!". After this, I tried this solution already on here: Python Coding - Vending machine - How to get the user to only enter certain coins? I thought this meant I needed to change my float(input()) and everything float to int, so changing 0.01 (1p) to 1. But, when I did, I stil got
'int' object has no attribute 'split'
When using it in this code
dict = {"KitKat":"80p", "Coca-Cola":"85p", "DairyMilk":"80p","Walkers Crisps":"90p"}
coins = ["1","2","5","10","20","50","100"]
def balance():
inp = int(input("Please enter your coins. Please enter in pence, for example 1 pound = 100"))
if any(int(coin) not in value for coin in inp.split()):
print("Machine doesn't accept these coins")
else:
print("Correct coin amount. The coins have been added to your balance")
fb = fb + coin
def items():
print (" 1. KitKat:" , dict['KitKat'])
print (" 2. Coca-Cola:", dict['Coca-Cola'])
print (" 3. Dairy Milk:", dict["DairyMilk"])
print (" 4. Walkers Crisps:", dict["Walkers Crisps"])
snack = 1 # need a while loop, ignore
fb = 0.00
balance()
print("Your full balance is",fb)