python自动售货机_自动售货机程序(计算必须插入的数量等)

我想写一个程序来模拟自动售货机,并根据支付的金额计算出零钱(必须退还给你)。考虑到成本,首先应该提示用户添加更多的钱,直到支付满足/超过成本。在

假设所有的零钱都是用硬币换的,硬币的面额是:1c,5c,10c,25c,$1

这是我的计划:x = eval(input("Enter the cost (in cents):\n"))

b = 0

for i in range(x+500):

if x<5 and x>=b:

b += 1

print("Deposit a coin or note (in cents):")

print(1)

diff = b-x

for i in range(diff):

onecents = diff//1

new_onecents = diff - (onecents*1)

print("Your change is:")

if onecents != 0:

print(onecents,"x 1c")

break

elif x<10 and x>=b:

b += 5

print("Deposit a coin or note (in cents):")

print(5)

diff = b-x

for i in range(diff):

fivecents = diff//5

ne

你可能感兴趣的:(python自动售货机)