Project Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

import sys

def Database():
import mysql.connector
mydb =
mysql.connector.connect(host='localhost',user='root',password='qaz123wsx',database
='apple')
mycursor = mydb.cursor()

print("Here are the products to look into databases:")


print("1. Iphone")
print("2. Ipad")
print("3. Apple Watch")
print("4. Macbook")

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

if comp == 1:
mycursor.execute("select * from iphone")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

elif comp == 2:
mycursor.execute("select * from ipad")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

elif comp == 3:
mycursor.execute("select * from watch")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

elif comp == 4:
mycursor.execute("select * from macbook")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

def update():
import mysql.connector
mydb =
mysql.connector.connect(host='localhost',user='root',password='qaz123wsx',database
='apple')
mycursor = mydb.cursor()
print("Here is list of options:")
print("1. Update the Price")
print("2. Upadte the quantity")
comp = int(input("Enter your choice:"))

if comp == 1:
print("Here are the products to modify databases:")
print("1. Iphone")
print("2. Ipad")
print("3. Apple Watch")
print("4. Macbook")
ch = int(input("Enter your choice:"))

if ch == 1:

mycursor.execute("select * from iphone")


myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new price of product:"))

query = "update iphone set Price={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif ch == 2:

mycursor.execute("select * from ipad")


myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new price of product:"))

query = "update ipad set Price={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif ch == 3:

mycursor.execute("select * from watch")


myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new price of product:"))

query = "update watch set Price={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif ch == 4:

mycursor.execute("select * from macbook")


myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new price of product:"))

query = "update macbook set Price={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif comp == 2:
print("Here are the products to modify databases:")
print("1. Iphone")
print("2. Ipad")
print("3. Apple Watch")
print("4. Macbook")
ch = int(input("Enter your choice:"))

if ch == 1:
mycursor.execute("select * from iphone")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new Quantity of product:"))

query = "update iphone set Quantity={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif ch == 2:
mycursor.execute("select * from ipad")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new Quantity of product:"))

query = "update ipad set Quantity={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

elif ch == 3:
mycursor.execute("select * from watch")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new Quantity of product:"))

query = "update watch set Quantity={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")
elif ch == 4:
mycursor.execute("select * from macbook")
myrecords = mycursor.fetchall()
for i in myrecords:
print(i)

x = input("Enter the brand of the product:")


y = input("Enter the name of the product:")
z = int(input("Enter the new Quantity of product:"))

query = "update macbook set Quantity={} ,Brand='{}' where


Model='{}'".format(z,x,y)
print(query)
mycursor.execute(query)
mydb.commit()
print("UPDATED")

while True:
print("WELCOME to Apple")
print("Enter your User ID and Password to accees store's database")
q = input("UserID:")
if q == "Owner" or "owner":
x = input("Password:")
if x == "qaz123wsx":
print("Welcome Mr.Owner")
print("")
print("Choose Operation:")
print("1. See Database")
print("2. Update DataBase")
choice = int(input("Enter your Choice:"))

if choice == 1:
Database()

elif choice == 2:
update()

gh = input("Enter any key to quit:")


sys.exit()

You might also like