flashjaysan

coffee-machine

May 6th, 2021
749
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MENU = {
  2.     "espresso": {
  3.         "ingredients": {
  4.             "water": 50,
  5.             "coffee": 18,
  6.         },
  7.         "cost": 1.5,
  8.     },
  9.     "latte": {
  10.         "ingredients": {
  11.             "water": 200,
  12.             "milk": 150,
  13.             "coffee": 24,
  14.         },
  15.         "cost": 2.5,
  16.     },
  17.     "cappuccino": {
  18.         "ingredients": {
  19.             "water": 250,
  20.             "milk": 100,
  21.             "coffee": 24,
  22.         },
  23.         "cost": 3.0,
  24.     }
  25. }
  26.  
  27. resources = {
  28.     "water": 300,
  29.     "milk": 200,
  30.     "coffee": 100,
  31.     "money": 0.0,
  32. }
  33.  
  34.  
  35. def check_resources(water, milk, coffee):
  36.     missing_resource = False
  37.     if water <= resources['water']:
  38.         print('Sorry there\'s not enough water.')
  39.         missing_resource = True
  40.     if milk <= resources['milk']:
  41.         print('Sorry there\'s not enough milk.')
  42.         missing_resource = True
  43.     if coffee <= resources['coffee']:
  44.         print('Sorry there\'s not enough coffee.')
  45.         missing_resource = True
  46.     return missing_resource
  47.  
  48.  
  49. def report():
  50.     print(f'Water: {resources["water"]}ml')
  51.     print(f'Milk: {resources["milk"]}ml')
  52.     print(f'Coffee: {resources["coffee"]}g')
  53.     print(f'Money: ${resources["money"]:.2f}')
  54.  
  55.  
  56. def get_coins():
  57.     print('Please insert coins.')
  58.     quarters = int(input('How many quarters?: '))
  59.     dimes = int(input('How many dimes?: '))
  60.     nickles = int(input('How many nickles?: '))
  61.     pennies = int(input('How many pennies?: '))
  62.     return quarters * 0.25 + dimes * 0.10 + nickles * 0.05 + pennies * 0.01
  63.  
  64.  
  65. def place(order):
  66.     if check_resources(MENU[order]['water'], MENU[order]['milk'], MENU[order]['coffee']):
  67.         cost = MENU[order]["cost"]
  68.         print(f'One {order} is ${cost:.2f}.')
  69.         amount = get_coins()
  70.         change = amount - cost
  71.         if change >= 0:
  72.             print(f'Here is ${change:.2f} in change.')
  73.             print(f'Here is your {order}. Enjoy!')
  74.             resources['money'] += cost
  75.         else:
  76.             print('Sorry that\'s not enough money. Money refunded.')
  77.  
  78.  
  79. def run():
  80.     order = input('What would you like? (espresso/latte/cappuccino): ')
  81.     if order == 'off':
  82.         shutdown = True
  83.     elif order == 'report':
  84.         report()
  85.     elif order != 'espresso' and order != 'latte' and order != 'cappuccino':
  86.         print('Sorry that\'s not available.')
  87.     else:
  88.         place(order)
  89.  
  90.  
  91. def coffee_machine():
  92.     shutdown = False
  93.     while not shutdown:
  94.         run()
  95.  
  96.  
  97. coffee_machine()
  98.  
RAW Paste Data