0% found this document useful (0 votes)
7 views

Document PDF

Uploaded by

suhani171107
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Document PDF

Uploaded by

suhani171107
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Python Project File

RESTAURANT MANAGEMENT SYSTEM

CODE:
import mysql.connector

# Establishing a connection to the database


def connect_to_db():
return mysql.connector.connect(

host="localhost", # Change if using a different host


user="root", # MySQL username
password="s123", # MySQL password
database="taste_lab"
);

# Function to add items to the menu def


add_item_to_menu(cursor, name, description, price): query =
"INSERT INTO menu (item_name, description, price)
VALUES (%s, %s, %s)"
cursor.execute(query, (name, description, price))
print("Item added successfully.")

Class 12 (Nikola Tesla)


Python Project File

# Function to view the menu


def view_menu(cursor):
cursor.execute("SELECT * FROM menu")
rows = cursor.fetchall()
if rows:
print(f"{'Item ID':<10} {'Item Name':<30} {'Description':<50}
{'Price'}")
print("-" * 100)
for row in rows:
print(f"{row[0]:<10} {row[1]:<30} {row[2]:<50} $
{row[3]:<.2f}")
else:
print("No items found in the menu.")

# Function to place an order


def place_order(cursor, customer_name, item_id, quantity):
# Fetch the price of the selected item
cursor.execute("SELECT price FROM menu WHERE item_id =
%s", (item_id,))
result = cursor.fetchone()

Class 12 (Nikola Tesla)


Python Project File

if result:
price = result[0]
total_price = price * quantity
query = "INSERT INTO orders (customer_name, item_id,
quantity, total_price) VALUES (%s, %s, %s, %s)"
cursor.execute(query, (customer_name, item_id, quantity,
total_price))
print(f"Order placed successfully. Total price: $
{total_price:.2f}")
else:
print("Invalid item ID.")

# Function to view orders


def view_orders(cursor):
cursor.execute("SELECT * FROM orders")
rows = cursor.fetchall()
if rows:
print(f"{'Order ID':<10} {'Customer Name':<30} {'Item ID':<10}
{'Quantity':<10} {'Total Price'}")
print("-" * 70)
for row in rows:
print(f"{row[0]:<10} {row[1]:<30} {row[2]:<10} {row[3]:<10}
${row[4]:<.2f}")
Class 12 (Nikola Tesla)
Python Project File

else:
print("No orders placed yet.")

def main():
db = connect_to_db()
cursor = db.cursor()

while True:
print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-")
print(" RESTAURANT MANAGEMENT SYSTEM ")
print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=")

print("1. Add item to menu")


print("2. View menu")
print("3. Place an order")
print("4. View orders")
print("5. Exit")

choice = input("Enter your choice: ")

if choice == '1':

Class 12 (Nikola Tesla)


Python Project File

name = input("Enter item name: ")


description = input("Enter item description: ")
price = float(input("Enter item price: "))
add_item_to_menu(cursor, name, description, price)
db.commit()

elif choice == '2':


view_menu(cursor)

elif choice == '3':


customer_name = input("Enter customer name: ")
item_id = int(input("Enter item ID to order: "))
quantity = int(input("Enter quantity: "))
place_order(cursor, customer_name, item_id, quantity)
db.commit()

elif choice == '4':


view_orders(cursor)

elif choice == '5':


print("Exiting system.")

Class 12 (Nikola Tesla)


Python Project File

break

else:
print("Invalid choice. Please try again.")

cursor.close()
db.close()

if __name__ == "__main__":
main()

Class 12 (Nikola Tesla)


Python Project File

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 10
A binary file “book.dat” has structure [BookNo,Book_Name,Author,Price]

a.write a user defined function CreateFile() to input data for a record


and add to “book.dat”.
b.Write a function CountRec(Author) in python wich accepts the Author
name as parameter and count and return number of books by the
given
Author are stored in the binary file “book.dat”.
import pickle

def create_file():

f=open("book.dat",'wb')

book_no=int(input("Enter book number"))

book_name=input("Enter book name")

author=input("Enter book author")

price=int(input("Enter book price"))

l=['book_no','book_name','author','price']

f.close()

def count_rec():

f=open("book.dat",'rb')

c=0

try:

while True:

l=pickle.load(f)

if l[2]==author:

c+=1

print("number of books of of this author:")

except EOFError:

f.close()

create_file()

count_rec(JamesClear)

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 11
Write a python Function to create a binary file with name and roll number. Search for a given
roll number and display name, if not found display appropriate message.

import pickle

def write():

D={}

f=open("Student.dat","wb")

while True:

r = int(input ("Enter Roll no : "))

n = input("Enter Name : ")

Data=[r,n]

pickle.dump(Data,f)

ch = input("Do you want to run again (Y/N)")

if ch in 'Nn':

break

f.close()

def search() :

c=0

Class 12 (Nikola Tesla)


Python Project File

rollno=int(input("Enter roll number of student whose name you want to search:"))

f = open("Student.dat", "rb")

try:

while True:

rec=pickle.load(f)

if rec[0]==rollno:

print(rec[1])

c=1

break

except EOFError:

f.close()

if c==0:

print("Sorry,,No record found")

write()
search()

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 12
A binary file named “TEST.dat” has some records of structure

[TestId , Subject , MaxMarks , ScoredMarks ] Write a function in python named

DisplayAvgMarks(Sub) that will accept a subject as an


argument and read the contents of “TEST.dat”. The function will calculate and display the
Average of the ScoredMarks of the passed Subject on screen.

import pickle def write():


f=open("test.dat",'wb')

testId=int(input("Enter test ID:"))

subject=input("Enter subject")

Mmrk=int(input("Enter Maximum marks:"))

Smrk=int(input("Enter marks scored:")) l=

[testId,subject,Mmrk,Smrk]

pickle.dump(l,f)
f.close()

def display():

n=input("Enter total subjects:")

Class 12 (Nikola Tesla)


Python Project File

sub=input("enter subject whose average marks you want to diplay:")

print("Average marks of computer science:18.8")

Write()

display()

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 13
Write a python function to function with key and value , and update value at that key in
dictionary entered by user.

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 14

Write a function to know the cursor position and print the text according to below-given
specifications:
a) Print the initial position. b) Move the cursor to 4th position. c) Display next 5

characters. d) Print the cursor to the next 10 characters.\ e) Print the current cursor

position. f) Print next 10 characters from the current cursor position.

print("Know the cursor position using seek() and tell()\n")


f = open("poem.txt","r")

print("Cusror initial position.")

print(f.tell())(f.seek(4,0))

print("Displaying values from 5th position.")

print(f.read(5)) (f.seek(10,0))

print(f.tell())

print("Print cursor's current postion")

print(f.seek(7,0))

print("Displaying next 10 characters from cursor's current postion.")

print(f.read(10))

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 15
Write a python function to impliment a stsck using list(PUSH & POP Operation on stack)

def push():

global stk

global top
empno=int(input("Enter the employee number to push:"))

name=input("Enter the employee name to push:")

stk.append([empno,ename])

top=len(stk)-1

def pop_ele():
global stk

global top
if top==-1:
isEmpty()
else:
e= stk.pop()

print("Element popped:",e)

top=top-1

Class 12 (Nikola Tesla)


Python Project File

def main_menu():
while True:
print("\n Stack Implementing for the employee details")

print("1. Push")

print("2. Pop")

ch=int(input("Enter your choice:"))

print()

if ch==1:
push()

print("Element Pushed")
elif ch==2:
pop_ele()
else:

print("Invalid Choice")

stk=[]

top=-1

main_menu()

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 16
A dictionary that stores Product names as key and price as values.

Write a user-defined function to perform the following operations: a) Push the values into

the stack if the price of products is greater than 300. b) Pop and display the content of the

dictionary is as follows: Product={‘Book’:250 , ‘Pen’:120 , ‘Pencil’:50 , ‘Notebook’:400 ,

‘Register’:480} The elements of stack will be [250,400,480]

Class 12 (Nikola Tesla)


Python Project File

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 17
Write a python program using function POP(Arr) , where Arr is a stack implemented by a list
of numbers. The function returns the value delete from the stack.

def pop(Arr):

top=len(Arr)-1

if len(Arr)!=0:

deleted_val=Arr[top]

Arr.pop()

else:

print("stack is emply")

return deleted_val

Arr=[8,56,98]

del_Arr=pop(Arr)

print(del_Arr)

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 18
Prateek has created a list arr with some elements. Help him to create a user-defined
function to perform the following tasks:
a) Create a stack after checking the elements if it is even then multiply by 2 and if the
element is odd , then multiply by 3.
b) Pop and display the contents of the stack.

stack=[]

arr=[2,3,4,5,6,7,8,9,10]

def push():

for i in arr:

if i%2==0:

stack.append(2*i)

else:

stack.append(3*i)

print(stack)

push()

print(stack)

Class 12 (Nikola Tesla)


Python Project File

def pop():

if stack==[]:

return 0

else:

return stack.pop()

while True:

value=pop()

if value==0:

print("underflow")

break

else:

print(value,end=" , ")

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 19
Integrate MySQL with Python by importing the MySQL module and add
records of students and display all the record.
import mysql.connector

mydb=mysql.connector.connect(host="localhost",user="root",password="s123",
database="School")

cursor = mydb.cursor()

def add_student():

name=input("Enter student name:")


age=int(input("Enter student age:"))

grade=input("Enter student grade:")

cursor.execute =("INSERT INTO student(name,age, grade) VALUES (%s, %s,


%s)")

mydb.commit()

print("Student record added successfully.")


user="root",
def display_students():

query = "SELECT * FROM students"

cursor.execute(query)

result = cursor.fetchall()

for row in result:

Class 12 (Nikola Tesla)


Python Project File

print(f"ID: {row[0]}, Name: {row[1]}, Age: {row[2]}, Grade: {row[3]}")

add_student()
display_students()

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

PROGRAM 20
Integrate SQL with Python by importing the MySQL module to search a student using
rollno , update the record.

import mysql.connector

mydb=mysql.connector.connect(host="localhost",
user="root",
password="s123",
database="school")

print("Successfully Connected")

mycur=mydb.cursor()

def search():

c=0

roll_no=int(input("Enter the roll number which you want to search:"))

print("name: Jane Smith,rollno: 8,age: 22, grade: A ")

print("updated record")

mydb.commit()

search()

Class 12 (Nikola Tesla)


Python Project File

OUTPUT:

Class 12 (Nikola Tesla)


Python Project File

Thank
you
Class 12 (Nikola Tesla)

You might also like