You are on page 1of 7

Input code :-

import pymysql

def menu():
more='yes'
print("1. Create items table")
print("2. Create Customers table")
print("3. Add customer data")
print("4. Generate invoice")
print("5. Exit")
while more=='yes':
a=int(input("Enter your choice: "))
if a==1:
fun1()
elif a==2:
fun2()
elif a==3:
fun4()
elif a==4:
fun5()
else:
break

def fun1():
con=pymysql.connect(host='localhost', user='root', passwd="123", db='baker
y')
cur=con.cursor()
i="create table items(icode int(3), iname char(20), price float(5,2));"
cur.execute(i)
i1="insert into items values(1,'Pasteries', 100.00);"
cur.execute(i1)
con.commit()
i2="insert into items values(2,'Snacks', 200.00);"
cur.execute(i2)
con.commit()
i3="insert into items values(3,'Chocolates', 100.00);"
cur.execute(i3)
con.commit()
i4="insert into items values(4,'Beverages', 100.00);"
cur.execute(i4)
con.commit()
i5="insert into items values(5,'Ice Creams', 100.00);"
cur.execute(i5)
con.commit()
cur.close()
con.close()

def fun2():
con=pymysql.connect(host='localhost', user='root', passwd="123", db='baker
y')
cur=con.cursor()
cur.execute("create table customer(cname char(20), ctc char(10), icode int
(3), iname char(20), iflav char(20),amt int(5));")
cur.close()
con.close()

def fun3():
con=pymysql.connect(host='localhost', user='root',passwd="123", db='bakery
')
print("WELCOME TO MYLO'S BAKERY HOUSE")
print("MENU")
cur=con.cursor()
x="select*from items;"
cur.execute(x)
y=cur.fetchall()
for i in y:
print(i)
cur.close()
con.close()

def fun4():
con=pymysql.connect(host='localhost', user='root',passwd="123", db='bakery
')
cur=con.cursor()
ans='yes'
amt=0
while ans=='yes':
n=input("Customer name: ")
ctc=input("Contact number: ")
fun3()
item=int(input("What would you like to have? "))

if(item==1):
iname='Pastry'
l1=['Chocolate', 'Vanilla','Black Forest', 'Pineapple', 'Buttersco
tch']
print("Choose a flavour:")
for i in l1:
print(i)
print("")
flavour=input("Which flavour would you like? ")
if flavour in l1:
amt=100.00
print("")
print("Your order has been placed!")

elif(item==2):
iname='snack'
l2=['Cheese Pizza', 'Red Pasta', 'Burger','Vegetable Sandwich', 'C
heese Sandwich']
print("Choose a snack:")
for i in l2:
print(i)
print("")
flavour=input("Which snack would you like? ")
if flavour in l2:
amt=200.00
print("")
print("Your order has been placed!")

elif(item==3):
iname='Chocolate'
l3=['Dark', 'Milk', 'Mint','Almond']
print("Choose a chocolate:")
for i in l3:
print(i)
print("")
flavour=input("Which chocolate would you like? ")
if flavour in l3:
amt=50.00
print("")
print("Your order has been placed!")

elif(item==4):
iname="Beverages"
l4=['Tea','MilkCoffee','BlackCoffee','MangoJuice','OrangeJuice','A
ppleJuice','Cola']
print("Choose a beverage:")
for i in l4:
print(i)
print("")
flavour=input("Which beverage would you like? ")
if flavour in l4:
amt=100.00
print("")
print("Your order has been placed!")

elif(item==5):
iname='Ice cream'
l5=['Chocochip','Chocolate','Vanilla','Mango','Butterscotch','Stra
wberry']
print("Choose an ice cream flavour:")
for i in l5:
print(i)
print("")
flavour=input("Which ice cream would you like? ")
if flavour in l5:
amt=100.00
print("")
print("Your order has been placed!")

cur.execute("insert into customer values (%s,%s,%s,%s,%s,%s)", (n,ctc,


item,iname,flavour,amt))
con.commit()
ans=input("Do you want to order more? ")

def fun5():
con=pymysql.connect(host='localhost', user='root',passwd="123", db='bakery
')
cur=con.cursor()
print("INVOICE")
print("")
p="select cname as name, iname as itemname, iflav as itemtype, sum(amt) as
totalamt from customer group by cname;"
cur.execute(p)
q=cur.fetchall()
print("Name Item Type/Flavour Total amount")
for i in q:
print(i)
cur.close()
con.close()
menu()

Output of code:-
1. Create items table
2. Create Customers table
3. Add customer data
4. Generate invoice
5. Exit
Enter your choice: 1
Enter your choice: 2
Enter your choice: 3
Customer name: Mylo
Contact number: 123
WELCOME TO MYLO'S BAKERY HOUSE
MENU
(1, 'Pasteries', 100.0)
(2, 'Snacks', 200.0)
(3, 'Chocolates', 100.0)
(4, 'Beverages', 100.0)
(5, 'Ice Creams', 100.0)
What would you like to have? 1
Choose a flavour:
Chocolate
Vanilla
Black Forest
Pineapple
Butterscotch

Which flavour would you like? Black Forest

Your order has been placed!


Do you want to order more? yes
Customer name: Mylo
Contact number: 123
WELCOME TO MYLO'S BAKERY HOUSE
MENU
(1, 'Pasteries', 100.0)
(2, 'Snacks', 200.0)
(3, 'Chocolates', 100.0)
(4, 'Beverages', 100.0)
(5, 'Ice Creams', 100.0)
What would you like to have? 5
Choose an ice cream flavour:
Chocochip
Chocolate
Vanilla
Mango
Butterscotch
Strawberry

Which ice cream would you like? Mango

Your order has been placed!


Do you want to order more? yes
Customer name: Shylo
Contact number: 456
WELCOME TO MYLO'S BAKERY HOUSE
MENU
(1, 'Pasteries', 100.0)
(2, 'Snacks', 200.0)
(3, 'Chocolates', 100.0)
(4, 'Beverages', 100.0)
(5, 'Ice Creams', 100.0)
What would you like to have? 4
Choose a beverage:
Tea
MilkCoffee
BlackCoffee
MangoJuice
OrangeJuice
AppleJuice
Cola

Which beverage would you like? Cola

Your order has been placed!


Do you want to order more? yes
Customer name: Shylo
Contact number: 456
WELCOME TO MYLO'S BAKERY HOUSE
MENU
(1, 'Pasteries', 100.0)
(2, 'Snacks', 200.0)
(3, 'Chocolates', 100.0)
(4, 'Beverages', 100.0)
(5, 'Ice Creams', 100.0)
What would you like to have? 2
Choose a snack:
Cheese Pizza
Red Pasta
Burger
Vegetable Sandwich
Cheese Sandwich

Which snack would you like? Cheese Sandwich

Your order has been placed!


Do you want to order more? no
Enter your choice: 4
INVOICE

Name Item Type/Flavour Total amount


('Mylo', 'Pastry', 'Black Forest', Decimal('200'))
('Shylo', 'Beverages', 'Cola', Decimal('300'))
Enter your choice: 5

You might also like