top of page

Coffee machine coding

  • Writer: 라임 샹큼
    라임 샹큼
  • Mar 7
  • 3 min read

from menu import MENU,resources


revenue = 0


def count_money(_):

    global revenue

    quarters = 0.25 * int(input('Quarters:'))

    dimes = 0.10 * int(input('Dimes:'))

    nickles = 0.05 * int(input('nickles:'))

    pennies = 0.01 * int(input('Pennies:'))

    t = quarters + dimes + nickles + pennies

    total = round(t,2)

    if _ in ['espresso', 'latte', 'cappuccino']:

        if total == MENU[_]['cost']:

            revenue += total

            return 1

        elif total > MENU[_]['cost']:

            revenue += round(MENU[_]['cost'],2)

            print('That\'s more than enough')

            print(f'${round(total-MENU[_]['cost'],2)} returned')

            return 1

        else:

            print('Not enough money')

            return 0



def make_drink():

    resources_water = resources['water']

    resources_milk = resources['milk']

    resources_coffee = resources['coffee']

    continual = True

    while continual:


        first_instruction = input('What would you like?: espresso/latte/cappuccino').lower()

        if first_instruction == 'off':

            continual = False

        elif first_instruction == 'report':


            print(f'''

    water : {resources_water}

    milk: {resources_milk}

    coffee: {resources_coffee}

    money : ${revenue}''')


        #espresso drink order

        elif first_instruction == 'espresso':

            espresso_water = MENU['espresso']['ingredients']['water']

            espresso_coffee = MENU['espresso']['ingredients']['coffee']

            if resources_water < espresso_water or resources_coffee < espresso_coffee:

                print('Sorry resource has been depleted')

                continual = False


            if continual != False:

                if count_money(first_instruction) == 1:

                    resources_water -= espresso_water

                    resources_coffee -= espresso_coffee

                    print('Enjoy your drink')


        #latte drink order

        elif first_instruction == 'latte':

            latte_water = MENU['latte']['ingredients']['water']

            latte_coffee = MENU['latte']['ingredients']['coffee']

            latte_milk = MENU['latte']['ingredients']['milk']

            if resources_water < latte_water or resources_coffee < latte_coffee or resources_milk < latte_milk:

                print('Sorry resource has been depleted')

                continual = False


            if continual != False:

                if count_money(first_instruction) == 1:

                    resources_water -= latte_water

                    resources_coffee -= latte_coffee

                    resources_milk -= latte_milk

                    print('Enjoy your drink')


        #cappuccino drink

        elif first_instruction == 'cappuccino':

            cappuccino_water = MENU['cappuccino']['ingredients']['water']

            cappuccino_coffee = MENU['cappuccino']['ingredients']['coffee']

            cappuccino_milk = MENU['cappuccino']['ingredients']['milk']

            if resources_water < cappuccino_water or resources_coffee < cappuccino_coffee or resources_milk < cappuccino_milk:

                print('Sorry resource has been depleted')

                continual = False


            if continual != False:

                if count_money(first_instruction) == 1:

                    resources_water -= cappuccino_water

                    resources_coffee -= cappuccino_coffee

                    resources_milk -= cappuccino_milk

                    print('Enjoy your drink')




make_drink()


Recent Posts

See All
Reading and writing files

I learned how to read write txt files. I learned how to navigate files. I always wondered how people sent automated emails to so many...

 
 
 
Ping-Pong game

This project really helped me understand OOP more and grasp the concept of inheritance in classes. screen = Screen() screen.setup(height...

 
 
 
Making the well-known Snake game

Everyone has atleast had one instance in which they downloaded snake.io on their phone and had a few goes at it. I wanted to replicate...

 
 
 

Comments


© 2024 by GifTED. Powered and secured by Wix

bottom of page