DEV Community

Cover image for Day 13 of My AI & Data Mastery Journey: From Python to Generative A
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 13 of My AI & Data Mastery Journey: From Python to Generative A

PROJECT

Coffee Machine

Define Menu and Resources

Set menu items with required ingredients and cost for each :espresso, latte, cappuccino

Set initial available resources for water, milk, coffee

Set initial profit to zero
Enter fullscreen mode Exit fullscreen mode

Main Program Loop

While machine is ON:

    Ask user: "What would you like? (espresso/latte/cappuccino)"

    If user types "off":

        Turn machine OFF and exit loop

    If user types "report":

        Display current resource levels and money earned (profit)

        Repeat loop

    Else:

        Retrieve drink details (ingredients and cost)
Enter fullscreen mode Exit fullscreen mode

Check Resource Sufficiency

For each required ingredient in drink:

    If available resource is less than needed:

        Print “Sorry, not enough [ingredient]”

        Skip to next loop

Otherwise, continue
Enter fullscreen mode Exit fullscreen mode

Process Coins

Ask user how many quarters, dimes, nickels, and pennies were inserted

Calculate the total money received
Enter fullscreen mode Exit fullscreen mode

Check Transaction Success

If money received is at least cost of drink:

    Calculate and give any change

    Add drink cost to profit

    Proceed to make coffee

Else:

    Print "Sorry, not enough money. Money refunded."

    Cancel transaction and loop again
Enter fullscreen mode Exit fullscreen mode

Make Coffee

Deduct the required ingredients from available resources

Print: "Here is your [drink]. Enjoy!"
Enter fullscreen mode Exit fullscreen mode

Features:

User can order drinks until machine is turned off

Machine checks resource levels before processing any order

Machine processes coin payments, checks if enough was inserted, and returns change if required

Generates a report of available resources and profit anytime requested
Enter fullscreen mode Exit fullscreen mode

Top comments (0)