[Algorithm 02] Vending Machine
※トップ画像はPixabayから引用しています
釣り銭計算
import sys
def keyboard_input(word='input'):
input_num = input('%s: ' % word)
if not input_num.isdecimal():
print('please input an integer withount comma')
sys.exit()
return input_num
input_price = keyboard_input('input')
product_price = keyboard_input('product')
change = int(input_price) - int(product_price)
if change < 0:
print('not enough money')
sys.exit()
coins = [10000, 5000, 1000, 500, 100, 50, 10, 5, 1]
for coin in coins:
rest = change // coin
change %= coin
print(str(coin) + ': ' + str(rest))
世界がよりよくなればいいな