Menu Ordering System Documentation

Introduction

This document provides an overview and explanation of the Python code that implements a simple menu ordering system. The code allows users to select items from a menu, calculate the total cost, apply tax, and add a tip. Code Overview

The code consists of several parts:

Menu Definition: The menu items and their corresponding prices are defined using a Python dictionary. The menu dictionary is structured as follows:

python

menu =  {
        "burger": 13.99,
        "wings": 9.50,
        "fries": 5.50,
        "chips": 1.99,
        "soda": 2.99,
        "cookie": 1.99,
        "salad": 9.99
        } 

Total Initialization:

The variable total is initialized to 0. This variable will be used to keep track of the total cost of the items selected by the user.

Displaying the Menu:

The code displays the menu to the user, listing each item and its price. This is done using a for loop that iterates through the items in the menu dictionary.

Ordering Loop:

The code enters a loop that allows the user to select items from the menu. It continues to prompt the user for orders until they choose to exit.

Order Selection:

Within the loop, the user is prompted to select an item from the menu using the input function. The selected item is stored in the item variable.

Calculating and Displaying Item Cost:

The code calculates the cost of the selected item by looking up its price in the menu dictionary and adds this cost to the total variable. It then displays the cost of the selected item.

Continuation Prompt:

After each order, the user is asked if they would like to buy anything else. The user’s response is stored in the yn variable. If the user enters ‘y’, the loop continues, allowing them to place additional orders.

Calculating Total Cost:

After the user finishes ordering, the code displays the total cost of all items ordered.

Calculating Tax:

The code calculates and displays the tax on the total cost. The tax rate is set at 7.25% (0.0725).

Entering Tip:

The user is prompted to enter a tip amount in percentage. The code removes any ‘%’ characters from the input, calculates the tip value as a percentage of the total cost, and displays the tip amount.

Calculating Final Total:

Finally, the code calculates and displays the grand total, including tax and tip.

Explanation of Code Details

Now, let’s explain some specific aspects of the code:

str(v): In the line print(k + " $" + str(v)), str(v) is used to convert the price (v) from a floating-point number to a string so that it can be concatenated with the item name and the '$' symbol for display purposes.

The loop that displays the menu items (for k, v in menu.items():) iterates through the menu dictionary, where k represents the item name (key) and v represents the item's price (value).

The round function is used to round the tax, tip, and final total values to two decimal places for clarity.

Example Usage

Here’s an example of how you might use this code:

The user is presented with a menu and selects items one by one, entering the item's name (e.g., "burger").
The code calculates the cost of each item and adds it to the running total.
After the user finishes ordering, the code calculates the tax on the total cost.
The user enters a tip amount (e.g., "10%").
The code calculates the final total, including tax and tip.
The final total is displayed to the user.

Conclusion

This Python code provides a simple menu ordering system that allows users to select items, calculate costs, apply tax, and add tips. It can be a useful starting point for creating more complex restaurant or ordering systems.

#Define dictionary containing all menu items and their corresponding cost 
#All costs are pre-Covid because no way we're getting prices this low anymore

menu =  {"burger": 13.99,
         "wings": 9.50,
         "fries": 5.50,
         "chips": 1.99,
         "soda": 2.99,
         "cookie": 1.99,
         "salad": 9.99}

#Sets the total cost of cart to 0 dollars
total = 0
#Shows the user all menu items and prompts them to select an item
print("Menu:")
print("-------------------------------")
for k,v in menu.items():
    print(k + "  $" + str(v))


#Defines variable "yn" to be used as the condition in the while loop
yn = "y"

#Check if yes/no or "yn" equals y meaning yes
#if yes, continue or redo the loop
while yn == "y":
    print("------------------------------------")

    #Ask the user which menu item they would like
    item = input("Please select an item from the menu")

    #Display the cost of the desired item
    print("cost of: " + 
          item)
    print("$" + str(menu[item]))

    #Add the cost of the desired menu item to the total bill for the day
    total += menu[item]

    #Ask valued customer once again whether they would like to buy anything else
    yn = input("Would you like to buy anything else? (y/n)")
Menu:
-------------------------------
burger  $3.99
wings  $3.5
fries  $2.5
chips  $1.99
soda  $0.99
------------------------------------
cost of: burger
$3.99
#Print cost of items without tax
print("Cost of items: " + str(total))

#Print total cost of items including tax
print("Tax: " + str(round(0.0725*total, 2)))

#Prompt user, asking for tip percentage for our amazing employees because they are so great
tip = input("Enter tip amount here: ")

#Make sure there aren't any percent symbols before adding to total
tip = tip.replace('%', '')

#Multiply percentage tip to find how much the stingy customer is tipping
tipval = (float(tip)*.01)*total

#Print how much the tip comes out to be
print("Tip: " + str(round(float(tipval), 2)) + " (" + tip + "%)")

#Print the total cost of the customer's amazing meal and experience
print("Total: " + str(round(1.0725*total, 2) + round(float(tipval), 2)))
Cost of items: 3.99
Tax: 0.29
Tip: 0.6 (15%)
Total: 4.88