def main(): vm = VendingMachine() vm.add_product(Product("水", 100)) vm.add_product(Product("ビール", 350)) vm.add_product(Product("コーラ", 120)) for id, product in vm.products.items(): print("%d) %s : %d 円" % (id, product.name, product.price)) id = int(input("購入する商品の番号を選んでください >> ")) while(True): input_str = input("お金を入れてください(0で止まります) >> ") try: if(input_str == "0"): break currency = Currency(int(input_str)) except ValueError as f: print("10, 50, 100, 500, 1000のどれかを指定してください。 ") continue vm.insert_money(currency) vm.buy(id) vm.return_change() print(f'現在の売り上げは{vm.profit}円です。')
from vending_machine import VendingMachine from drink import Drink if __name__ == '__main__': print('# 200円を入れて 0: COKE を購入') money = 200 drink_type = 0 vending_machine = VendingMachine() my_drink = vending_machine.buy(money, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink)) print('Change: {}'.format(change)) print('->100円か500円しか受け付けないのでそのまま返ってくる') print('# 500円を入れて 1: DIET_COKE を購入') money = 500 drink_type = 1 vending_machine = VendingMachine() my_drink = vending_machine.buy(money, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink.get_kind())) print('Change: {}'.format(change)) print('->DIET_COKEが出て400円返ってくる')
from vending_machine import VendingMachine if __name__ == '__main__': print('# 200円を入れて 0: COKE を購入') money = 200 drink_type = 0 vending_machine = VendingMachine() my_drink = vending_machine.buy(money, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink)) print('Change: {}'.format(change)) print('->100円か500円しか受け付けないのでそのまま返ってくる') print('# 500円を入れて 1: DIET_COKE を購入') money = 500 drink_type = 1 vending_machine = VendingMachine() my_drink = vending_machine.buy(money, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink.get_kind())) print('Change: {}'.format(change)) print('->DIET_COKEが出て400円返ってくる')
from vending_machine import VendingMachine from currency import Yen100Coin from currency import Yen500Coin from drink import Coke from drink import DietCoke from payment import Payment if __name__ == '__main__': print('# 200円を入れて 0: COKE を購入') payment = Payment([Yen100Coin(), Yen100Coin()]) drink_type = Coke vending_machine = VendingMachine() my_drink = vending_machine.buy(payment, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink)) print('Change: {}'.format(change)) print('->100円か500円しか受け付けないのでそのまま返ってくる') print('# 500円を入れて 1: DIET_COKE を購入') payment = Payment([Yen500Coin()]) drink_type = DietCoke vending_machine = VendingMachine() my_drink = vending_machine.buy(payment, drink_type) change = vending_machine.refund() print('Drink: {}'.format(my_drink)) print('Change: {}'.format(change)) print('->DIET_COKEが出て400円返ってくる')
from drink import Drink from coin_holder import CoinHolder from vending_machine import VendingMachine from coin import Coin if __name__ == '__main__': my_vending_machine = VendingMachine() coins = CoinHolder(yen_500=0, yen_100=12, yen_10=10) my_drink = my_vending_machine.buy(coins, Drink.COKE) refund = my_vending_machine.refund() print("my_drink:", my_drink) print("refund: ", refund.__dict__) print("vending_coins: ", my_vending_machine.vending_coin_holder.coin_holder.__dict__) print("vending_drinks: ", my_vending_machine.drink_holder.__dict__) for coins in Coin: print()
from vending_machine import VendingMachine from drink import Drink if __name__ == '__main__': money = 200 drinkType = 0 vendingMachine = VendingMachine() myDrink = vendingMachine.buy(money, drinkType) change = vendingMachine.refund() print(myDrink) print(change)