Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MENU = {
- "espresso": {
- "ingredients": {
- "water": 50,
- "coffee": 18,
- },
- "cost": 1.5,
- },
- "latte": {
- "ingredients": {
- "water": 200,
- "milk": 150,
- "coffee": 24,
- },
- "cost": 2.5,
- },
- "cappuccino": {
- "ingredients": {
- "water": 250,
- "milk": 100,
- "coffee": 24,
- },
- "cost": 3.0,
- }
- }
- resources = {
- "water": 300,
- "milk": 200,
- "coffee": 100,
- "money": 0.0,
- }
- def check_resources(water, milk, coffee):
- missing_resource = False
- if water <= resources['water']:
- print('Sorry there\'s not enough water.')
- missing_resource = True
- if milk <= resources['milk']:
- print('Sorry there\'s not enough milk.')
- missing_resource = True
- if coffee <= resources['coffee']:
- print('Sorry there\'s not enough coffee.')
- missing_resource = True
- return missing_resource
- def report():
- print(f'Water: {resources["water"]}ml')
- print(f'Milk: {resources["milk"]}ml')
- print(f'Coffee: {resources["coffee"]}g')
- print(f'Money: ${resources["money"]:.2f}')
- def get_coins():
- print('Please insert coins.')
- quarters = int(input('How many quarters?: '))
- dimes = int(input('How many dimes?: '))
- nickles = int(input('How many nickles?: '))
- pennies = int(input('How many pennies?: '))
- return quarters * 0.25 + dimes * 0.10 + nickles * 0.05 + pennies * 0.01
- def place(order):
- if check_resources(MENU[order]['water'], MENU[order]['milk'], MENU[order]['coffee']):
- cost = MENU[order]["cost"]
- print(f'One {order} is ${cost:.2f}.')
- amount = get_coins()
- change = amount - cost
- if change >= 0:
- print(f'Here is ${change:.2f} in change.')
- print(f'Here is your {order}. Enjoy!')
- resources['money'] += cost
- else:
- print('Sorry that\'s not enough money. Money refunded.')
- def run():
- order = input('What would you like? (espresso/latte/cappuccino): ')
- if order == 'off':
- shutdown = True
- elif order == 'report':
- report()
- elif order != 'espresso' and order != 'latte' and order != 'cappuccino':
- print('Sorry that\'s not available.')
- else:
- place(order)
- def coffee_machine():
- shutdown = False
- while not shutdown:
- run()
- coffee_machine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement