Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Online Food Ordering System in Python with Source Code - How To

Online Food Ordering System in Python with Source Code

Posted on October 2, 2024October 2, 2024 By Rishabh saini No Comments on Online Food Ordering System in Python with Source Code

Online Food Ordering System in Python

In today’s fast-paced world, online food ordering systems have become essential for convenience and efficiency. This blog post demonstrates how to build a simple Online Food Ordering System using Python, without any graphical user interface. Instead, it operates via a command-line interface, focusing on core functionalities like viewing the menu, adding items to a cart, and calculating the total cost. This project offers a hands-on way to explore Python, database management, and basic user interaction.

Table of Contents

  • Online Food Ordering System in Python
    • Tools
    • Features
    • Python Code for the Online Food Ordering System
    • How the Code Works
      • 1. Database Setup:
      • 2. Menu Display:
      • 3. Adding to Cart:
      • 4. Viewing Cart:
      • 5. Placing the Order:
      • 6. Main Loop:
    • Running the System
    • Key Takeaways

Tools

  • Python: The language in which the application was written in programming.
  • SQLite: A lightweight, serverless database to store food items and their prices.
  • Command Line Interface: A text-based interface that allows users to interact with the system.

PHP PROJECT:- CLICK HERE

Features

  • View Menu: Display a list of available food items and their prices.
  • Add to Cart: Select food items and add them to a shopping cart.
  • Order Calculation: Determine the total cost of the cart’s contents.
  • Checkout: Place the order and show a summary with the total price.
https://updategadh.com/python-projects/top-10-final-year-project-ideas/

Python Code for the Online Food Ordering System

Here’s the complete source code for a command-line-based Online Food Ordering System:

import sqlite3

# Connect to SQLite database
conn = sqlite3.connect('food_ordering.db')
cursor = conn.cursor()

# Create food_items table if not exists
cursor.execute('''
CREATE TABLE IF NOT EXISTS food_items (
    item_id INTEGER PRIMARY KEY AUTOINCREMENT,
    item_name TEXT NOT NULL,
    item_price REAL NOT NULL
)
''')

# Insert sample food items if the table is empty
cursor.execute("SELECT COUNT(*) FROM food_items")
if cursor.fetchone()[0] == 0:
    cursor.execute("INSERT INTO food_items (item_name, item_price) VALUES ('Pizza', 10.99)")
    cursor.execute("INSERT INTO food_items (item_name, item_price) VALUES ('Burger', 5.99)")
    cursor.execute("INSERT INTO food_items (item_name, item_price) VALUES ('Pasta', 7.99)")
    conn.commit()

# Cart to store selected items
cart = []

# Function to display the menu
def show_menu():
    cursor.execute("SELECT item_id, item_name, item_price FROM food_items")
    items = cursor.fetchall()

    print("\n--- Menu ---")
    for item in items:
        print(f"{item[0]}. {item[1]} - ${item[2]:.2f}")

# Function to add an item to the cart
def add_to_cart(item_id, quantity):
    cursor.execute("SELECT item_name, item_price FROM food_items WHERE item_id = ?", (item_id,))
    item = cursor.fetchone()

    if item:
        cart.append((item[0], item[1], quantity))
        print(f"\nAdded {quantity} x {item[0]} to the cart.")
    else:
        print("Item not found!")

# Function to display the cart
def show_cart():
    if not cart:
        print("\nYour cart is empty!")
        return

    print("\n--- Your Cart ---")
    total = 0
    for item in cart:
        total += item[1] * item[2]
        print(f"{item[2]} x {item[0]} - ${item[1]:.2f} each")

    print(f"\nTotal: ${total:.2f}")

# Function to place an order
def place_order():
    if not cart:
        print("\nYour cart is empty! Please add items to your cart before placing an order.")
        return

    total = sum([item[1] * item[2] for item in cart])
    print("\n--- Order Summary ---")
    for item in cart:
        print(f"{item[2]} x {item[0]} - ${item[1]:.2f} each")

    print(f"\nTotal: ${total:.2f}")
    print("Thank you for your order!")

    cart.clear()  # Clear the cart after placing the order

# Main function to run the system
def main():
    while True:
        print("\n--- Food Ordering System ---")
        print("1. View Menu")
        print("2. Add Item to Cart")
        print("3. View Cart")
        print("4. Place Order")
        print("5. Exit")

        choice = input("\nChoose an option: ")

        if choice == '1':
            show_menu()
        elif choice == '2':
            item_id = int(input("Enter the item ID to add to your cart: "))
            quantity = int(input("Enter the quantity: "))
            add_to_cart(item_id, quantity)
        elif choice == '3':
            show_cart()
        elif choice == '4':
            place_order()
        elif choice == '5':
            print("Exiting system. Goodbye!")
            break
        else:
            print("Invalid option. Please try again.")

if __name__ == "__main__":
    main()

# Close the database connection after the program ends
conn.close()
Online Food Ordering System in Python
Online Food Ordering System in Python
Online Food Ordering System in Python
Online Food Ordering System in Python
Online Food Ordering System in Python
Online Food Ordering System in Python
Online Food Ordering System in Python with Source Code

How the Code Works

New Project :-https://www.youtube.com/@Decodeit2

1. Database Setup:

  • The system uses SQLite to store food items. When the program runs for the first time, it creates a table (food_items) and inserts a few sample items like pizza, burger, and pasta.
  • The database is queried whenever a user views the menu or adds items to the cart.

2. Menu Display:

  • The show_menu() function fetches all items from the database and displays them to the user in the terminal. The items include an ID, name, and price.

3. Adding to Cart:

  • Users can add food items to their cart by selecting an item ID and specifying a quantity. The add_to_cart() function ensures that the item is valid and adds it to the cart.

4. Viewing Cart:

  • The show_cart() function displays the contents of the cart along with the total price. Users can view their selected items before placing the order.

5. Placing the Order:

  • Once the user is ready, they can place the order. The place_order() function calculates the total price of the cart, displays the order summary, and clears the cart.

6. Main Loop:

  • The system runs in a loop where users can choose to view the menu, add items to the cart, view the cart, place an order, or exit the program.

Running the System

To run this system, you need to have Python installed on your machine. If you’re using Python 3, follow these steps:

  1. Save the code in a file, for example, food_ordering_system.py.
  2. Open a terminal and navigate to the directory where the file is located.
  3. Run the script using:
   python3 food_ordering_system.py

The program will start running, and you can interact with it through the command line.

Key Takeaways

  • SQLite Integration: The system interacts with an SQLite database to store and retrieve food items, demonstrating basic database management in Python.
  • Command-Line Interface: While there’s no graphical user interface, the system is fully functional and allows users to interact with the menu and cart through text input.
  • Modular Functions: The system is structured using modular functions, making it easier to maintain and extend.

  • Online Food Ordering System in Python with Source Code
  • Online Food Ordering System in Python
Post Views: 1,904
code Snippets Tags:food ordering system in python, food ordering system python project source code, online food ordering system, online food ordering system in django, online food ordering system in php, online food ordering system in python, online food ordering system in python django, online food ordering system in python github, online ordering system, ordering system in python, Python

Post navigation

Previous Post: Top 10 Final Year Project Ideas in Python
Next Post: Online Learning Management System with Source Code

More Related Articles

Online Shopping System using PHP, MySQL with Free Source Code Online Shopping System using PHP, MySQL with Free Source Code code Snippets
Sports Club Management System With Free Code - Sports Club Sports Club Management System With Free Code code Snippets
Supplier Management System in Java with Free Code - Supplier Management system Supplier Management System in Java with Free Code code Snippets

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Supply Chain Management PHP and CSS
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. F1 Race Road Game in Python Free Source Code
  4. Supplier Management System in Java with Free Code
  5. Create Address Book in Python with Source Code
  6. Contact Management in Python with Source Code

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,613)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,211)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,866)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme