{"id":4239,"date":"2023-11-04T12:32:12","date_gmt":"2023-11-04T07:02:12","guid":{"rendered":"https:\/\/cbsepython.in\/?p=4239"},"modified":"2023-11-04T12:37:04","modified_gmt":"2023-11-04T07:07:04","slug":"food-order-system-python-project","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/food-order-system-python-project\/","title":{"rendered":"Food Order System Python Project Class 12"},"content":{"rendered":"<h2><span style=\"color: #000000;\">Food Order System Python Project<\/span><\/h2>\n<p><span style=\"color: #000000;\">Here is a Python Project for managing a database related to a food ordering system. It uses the MySQL database system to store information about employees, customers, food items, and food orders. The code defines tables for Employee, Customer, Food and OrderFood. It allows you to add records to these tables and view them. Here is an overview of the code&#8217;s functionality and structure:<\/span><\/p>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Importing necessary modules:<\/strong> The code imports the <strong>connector<\/strong> module for working with the MySQL database.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Database connection:<\/strong> It establishes a connection to a MySQL database hosted on the local machine with the username &#8220;root&#8221; and password &#8220;admin&#8221;.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Creating tables:<\/strong> The code creates several tables within the &#8220;food1&#8221; database, including Employee, Customer, Food and OrderFood. These tables define the structure of the data that will be stored in the database.<\/span><\/li>\n<li><strong><span style=\"color: #000000;\">Functions for data entry:<\/span><\/strong>\n<ul>\n<li><span style=\"color: #000000;\"><strong>Customer()<\/strong>: Allows you to add a customer&#8217;s information to the &#8220;Customer&#8221; table.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Employee()<\/strong>: Allows you to add an employee&#8217;s information to the &#8220;Employee&#8221; table.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Food()<\/strong>: Lets you add food item details to the &#8220;Food&#8221; table.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>OrderFood()<\/strong>: Allows you to add an order for food to the &#8220;OrderFood&#8221; table.<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>View function:<\/strong> The <strong>View()<\/strong> function lets you search for and display records based on different search criteria, such as employee details, customer details, food items, or food orders.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>MenuSet function:<\/strong> This function displays a menu with options to add records or view data. You can choose an option by entering a corresponding number.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>RunAgain function:<\/strong> After performing an action, the script asks if you want to run the program again. If you choose &#8220;Y,&#8221; the menu is displayed again.<\/span><\/li>\n<\/ol>\n<p><span style=\"color: #000000;\">To use the script, you would execute it in a Python environment with the necessary MySQL connector library installed. It provides a simple command-line interface for interacting with the database.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><strong>Source Code:<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import os\r\nimport platform\r\nimport mysql.connector\r\nimport pandas as pd\r\n\r\n\r\nmydb = mysql.connector.connect(host=\"localhost\", user=\"root\", password=\"admin\")\r\n\r\n#creating DB\r\n\r\nmycursor = mydb.cursor()\r\nmycursor.execute(\"create database if not exists food1\")\r\nmycursor.execute(\"use food1\")\r\n\r\n#creating Tables\r\n\r\n# Define the Employee table\r\nmycursor.execute(\"\"\"\r\nCREATE TABLE IF NOT EXISTS Employee (\r\n    Emp_id INT AUTO_INCREMENT PRIMARY KEY,\r\n    ename VARCHAR(255) NOT NULL,\r\n    emp_g VARCHAR(10),\r\n    eage INT,\r\n    emp_phone BIGINT,\r\n    pwd VARCHAR(255)\r\n)\r\n\"\"\")\r\n\r\n# Define the Customer table\r\nmycursor.execute(\"\"\"\r\nCREATE TABLE IF NOT EXISTS Customer (\r\n    c_id INT AUTO_INCREMENT PRIMARY KEY,\r\n    name VARCHAR(255) NOT NULL,\r\n    cphone BIGINT,\r\n    payment INT,\r\n    pstatus VARCHAR(20),\r\n    email VARCHAR(255),\r\n    orderid INT,\r\n    date DATE\r\n)\r\n\"\"\")\r\n\r\n# Define the Food table\r\nmycursor.execute(\"\"\"\r\nCREATE TABLE IF NOT EXISTS Food (\r\n    Food_id INT AUTO_INCREMENT PRIMARY KEY,\r\n    Foodname VARCHAR(255) NOT NULL,\r\n    Food_size VARCHAR(20),\r\n    prize INT\r\n)\r\n\"\"\")\r\n\r\n# Define the OrderFood table\r\nmycursor.execute(\"\"\"\r\nCREATE TABLE IF NOT EXISTS OrderFood (\r\n    Orderf_id INT AUTO_INCREMENT PRIMARY KEY,\r\n    C_id INT,\r\n    Emp_id INT,\r\n    Food_id INT,\r\n    Food_qty INT,\r\n    Total_price INT\r\n)\r\n\"\"\")\r\n\r\n# Define the fee table\r\nmycursor.execute(\"\"\"\r\nCREATE TABLE IF NOT EXISTS fee (\r\n    roll INT AUTO_INCREMENT PRIMARY KEY,\r\n    feedeposit INT,\r\n    month VARCHAR(10)\r\n)\r\n\"\"\")\r\n\r\n# main COde\r\n\r\n\r\n\r\ndef Customer():\r\n    L = []\r\n    c_id = int(input(\"Enter the customer ID number: \"))\r\n    L.append(c_id)\r\n    name = input(\"Enter the Customer Name: \")\r\n    L.append(name)\r\n    cphone = int(input(\"Enter customer phone number: \"))\r\n    L.append(cphone)\r\n    payment = int(input(\"Enter payment method (1 for credit card, 2 for Debit Card): \"))\r\n    L.append(payment)\r\n    pstatus = input(\"Enter the payment status: \")\r\n    L.append(pstatus)\r\n    email = input(\"Enter the email id: \")\r\n    L.append(email)\r\n    orderid = input(\"Enter orderid: \")\r\n    L.append(orderid)\r\n    date = input(\"Enter the Date: \")\r\n    L.append(date)\r\n    cust = (L,)\r\n    sql = \"INSERT INTO customer (c_id, name, cphone, payment, pstatus, email, orderid, date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)\"\r\n    mycursor.execute(sql, cust)\r\n    mydb.commit()\r\n\r\n\r\ndef Employee():\r\n    L = []\r\n    Emp_id = int(input(\"Enter the Employee id: \"))\r\n    L.append(Emp_id)\r\n    ename = input(\"Enter the Employee Name: \")\r\n    L.append(ename)\r\n    emp_g = input(\"Enter Employee Gender: \")\r\n    L.append(emp_g)\r\n    eage = int(input(\"Enter Employee age: \"))\r\n    L.append(eage)\r\n    emp_phone = int(input(\"Enter employee phone number: \"))\r\n    L.append(emp_phone)\r\n    pwd = input(\"Enter the password: \")\r\n    L.append(pwd)\r\n    EMP = tuple(L)  # Convert the list to a tuple\r\n    sql = \"INSERT INTO Employee (Emp_id, ename, emp_g, eage, emp_phone, pwd) VALUES (%s, %s, %s, %s, %s, %s)\"\r\n    mycursor.execute(sql, EMP)\r\n    mydb.commit()\r\n\r\n\r\n\r\n\r\ndef Food():\r\n    L = []\r\n    Food_id = int(input(\"Enter the Food id: \"))\r\n    L.append(Food_id)\r\n    Foodname = input(\"Enter the Food Name: \")\r\n    L.append(Foodname)\r\n    Food_size = input(\"Enter Food size: \")\r\n    L.append(Food_size)\r\n    prize = int(input(\"Enter Prize of Food: \"))\r\n    L.append(prize)\r\n    Food = (L,)\r\n    sql = \"INSERT INTO Food (Food_id, Foodname, Food_size, prize) VALUES (%s, %s, %s, %s)\"\r\n    mycursor.execute(sql, Food)\r\n    mydb.commit()\r\n\r\n\r\ndef OrderFood():\r\n    L = []\r\n    Orderf_id = int(input(\"Enter the Food Order id: \"))\r\n    L.append(Orderf_id)\r\n    C_id = int(input(\"Enter the Customer id: \"))\r\n    L.append(C_id)\r\n    Emp_id = int(input(\"Enter Employee id: \"))\r\n    L.append(Emp_id)\r\n    Food_id = int(input(\"Enter Food id: \"))\r\n    L.append(Food_id)\r\n    Food_qty = int(input(\"Enter Qty: \"))\r\n    L.append(Food_qty)\r\n    Total_price = int(input(\"Enter Total_price: \"))\r\n    L.append(Total_price)\r\n    OrderFood = tuple(L)  # Convert the list to a tuple\r\n    sql = \"INSERT INTO OrderFood (Orderf_id, C_id, Emp_id, Food_id, Food_qty, Total_price) VALUES (%s, %s, %s, %s, %s, %s)\"\r\n    mycursor.execute(sql, OrderFood)\r\n    mydb.commit()\r\n\r\n\r\n\r\ndef View():\r\n    print(\"Select the search criteria: \")\r\n    print(\"1. Employee\")\r\n    print(\"2. Customer\")\r\n    print(\"3. Food\")\r\n    print(\"4. Order Food\")\r\n    ch = int(input(\"Enter the choice 1 to 4: \"))\r\n\r\n    if ch == 1:\r\n        Emp_id = int(input(\"Enter Employee ID: \"))\r\n        sql = \"SELECT * FROM Employee WHERE Emp_id = %s\"\r\n        mycursor.execute(sql, (Emp_id,))\r\n        res = mycursor.fetchall()\r\n        for x in res:\r\n            print(x)\r\n    elif ch == 2:\r\n        c_name = input(\"Enter Customer Name: \")\r\n        sql = \"SELECT * FROM Customer WHERE name = %s\"\r\n        mycursor.execute(sql, (c_name,))\r\n        res = mycursor.fetchall()\r\n        for x in res:\r\n            print(x)\r\n    elif ch == 3:\r\n        sql = \"SELECT * FROM Food\"\r\n        mycursor.execute(sql)\r\n        res = mycursor.fetchall()\r\n        for x in res:\r\n            print(x)\r\n    elif ch == 4:\r\n        food_id = int(input(\"Enter Food ID: \"))\r\n        sql = \"SELECT * FROM OrderFood WHERE Food_id = %s\"\r\n        mycursor.execute(sql, (food_id,))\r\n        res = mycursor.fetchall()\r\n        for x in res:\r\n            print(x)\r\n\r\n\r\n\r\ndef MenuSet():\r\n    print(\"Enter 1 to Add Employee\")\r\n    print(\"Enter 2 to Add Customer details\")\r\n    print(\"Enter 3 to Add Food Details\")\r\n    print(\"Enter 4 for Food Order\")\r\n    print(\"Enter 5 to view Food booking\")\r\n    \r\n\r\n    try:\r\n        userInput = int(input(\"Please Select an above option: \"))\r\n    except ValueError:\r\n        exit(\"\\nHey! That's Not A Number\")\r\n    else:\r\n        print(\"\\n\")\r\n\r\n        if userInput == 1:\r\n            Employee()\r\n        elif userInput == 2:\r\n            Customer()\r\n        elif userInput == 3:\r\n            Food()\r\n        elif userInput == 4:\r\n            OrderFood()\r\n        elif userInput == 5:\r\n            View()\r\n        else:\r\n            print(\"Enter correct choice. . .\")\r\n\r\ndef runAgain():\r\n    runAgn = input(\"\\nWant to run again? (Y\/N): \")\r\n    while runAgn.lower() == 'y':\r\n        if platform.system() == \"Windows\":\r\n            os.system(\"cls\")\r\n        else:\r\n            os.system(\"clear\")\r\n        MenuSet()\r\n        runAgn = input(\"\\nWant to run again? (Y\/N): \")\r\n\r\nMenuSet()\r\nprint(\"Good Bye... HAVE A NICE DAY\")\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #000000;\">Sample Output:<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre>Enter 1 to Add Employee\r\nEnter 2 to Add Customer details\r\nEnter 3 to Add Food Details\r\nEnter 4 for Food Order\r\nEnter 5 to view Food booking\r\n\r\nPlease Select an above option: 1\r\n\r\nEnter the Employee id: 101\r\nEnter the Employee Name: John Doe\r\nEnter Employee Gender: Male\r\nEnter Employee age: 30\r\nEnter employee phone number: 1234567890\r\nEnter the password: securepwd\r\n\r\nWant to run again? (Y\/N): Y\r\n\r\nEnter 1 to Add Employee\r\nEnter 2 to Add Customer details\r\nEnter 3 to Add Food Details\r\nEnter 4 for Food Order\r\nEnter 5 to view Food booking\r\n\r\nPlease Select an above option: 5\r\nSelect the search criteria:\r\n1. Employee\r\n2. Customer\r\n3. Food\r\n4. Order Food\r\nEnter the choice 1 to 4: 1\r\n\r\nEnter Employee ID: 101\r\n(101, 'John Doe', 'Male', 30, 1234567890, 'securepwd')\r\n\r\nWant to run again? (Y\/N): N<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Food Order System Python Project Here is a Python Project for managing a database related to a food ordering system. It uses the MySQL database system to store information about employees, customers, food items, and food orders. The code defines tables for Employee, Customer, Food and OrderFood. It allows you to add records to these [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,20,43],"tags":[],"class_list":["post-4239","post","type-post","status-publish","format-standard","hentry","category-cbse-sample-papers-class-12","category-cbse-computer-science-with-python-class-12","category-python-projects"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/4239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=4239"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/4239\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=4239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=4239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=4239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}