CBSE COMPUTER SCIENCE
Відкрити в Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
Показати більше549
Підписники
Немає даних24 години
Немає даних7 днів
Немає даних30 день
Архів дописів
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [3/20/2022 11:37 PM]
Download Python packages from the link : https://www.lfd.uci.edu/~gohlke/pythonlibs/
OUTPUT:
================== RESTART: C:\Users\sml\Desktop\pywithsql.py ==================
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 1
Enter Employee Number :101
Enter Name :APPLE
Enter Department :CS
Enter Salary :18000
A RECORD INSERTED...
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 1
Enter Employee Number :102
Enter Name :MANGO
Enter Department :MC
Enter Salary :17000
A RECORD INSERTED...
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 1
Enter Employee Number :103
Enter Name :ORANGE
Enter Department :BC
Enter Salary :19000
A RECORD INSERTED...
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 5
EMPNO NAME DEPARTMENT SALARY
101 APPLE CS 18000.00
102 MANGO MC 17000.00
103 ORANGE BC 19000.00
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 2
Enter employee number to be updated 102
Enter salary to be updated 18000
A Record Updated
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 5
EMPNO NAME DEPARTMENT SALARY
101 APPLE CS 18000.00
102 MANGO MC 18000.00
103 ORANGE BC 19000.00
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 3
Enter employee number to be deleted102
Record(s) Deleted
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 5
EMPNO NAME DEPARTMENT SALARY
101 APPLE CS 18000.00
103 ORANGE BC 19000.00
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 4
Enter employee number to be searched103
EMPNO NAME DEPARTMENT SALARY
103 ORANGE BC 19000.00
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 4
Enter employee number to be searched105
Record not found
1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : 6
File closed successfully...
>>>
#Python with Mysql
import mysql.connector as mcr
cn = mcr.connect(host='127.0.0.1',user='root',password="admin")
cr = cn.cursor()
cr.execute("create database if not exists company")
cr.execute("use company")
cr.execute("create table if not exists employee(empno int(12),empname varchar(50),edept varchar(30),salary decimal(12,2))")
cn.commit()
choice=int(input("1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : "))
while choice!=0:
if choice==1: #INSERTING A RECORD
e = int(input("Enter Employee Number :"))
n = input("Enter Name :")
d = input("Enter Department :")
s = int(input("Enter Salary :"))
query="insert into employee values({},'{}','{}',{})".format(e,n,d,s)
cr.execute(query)
cn.commit()
print("A RECORD INSERTED...")
elif choice == 2: #UPDATING A RECORD
e=int(input("Enter employee number to be updated "))
s=int(input("Enter salary to be updated "))
query="update employee set salary={} where empno={}".format(s,e)
cr.execute(query)
print("A Record Updated ")
cn.commit()
elif choice == 3: #DELETING A RECORD
e=int(input("Enter employee number to be deleted"))
query="delete from employee where empno={}".format(e)
cr.execute(query)
print("Record(s) Deleted ")
cn.commit()
elif choice == 4: #SEARCHING A RECORD
e=int(input("Enter employee number to be searched"))
query="select * from employee where empno={}".format(e)
cr.execute(query)
result = cr.fetchall()
if cr.rowcount==0:
print("Record not found")
else:
print("EMPNO","NAME","DEPARTMENT","SALARY")
for row in result:
print(row[0],row[1],row[2],row[3])
cn.commit()
elif choice == 5: #DISPLAYING RECORDS
query="select * from employee"
cr.execute(query)
result = cr.fetchall()
print("EMPNO","NAME","DEPARTMENT","SALARY")
for row in result:
print(row[0],row[1],row[2],row[3])
cn.commit()
elif choice==6: #CLOSING DATABASE
cn.close()
print("File closed successfully...")
break
else:
print("Invalid Choice...")
choice=int(input("1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : "))
import mysql.connector as mcr
cn = mcr.connect(host='127.0.0.1',user='root',password="admin")
cr = cn.cursor()
cr.execute("create database if not exists company")
cr.execute("use company")
cr.execute("create table if not exists employee(empno int(12),empname varchar(50),edept varchar(30),salary decimal(12,2))")
cn.commit()
choice=int(input("1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : "))
while choice!=0:
if choice==1: #INSERTING A RECORD
e = int(input("Enter Employee Number :"))
n = input("Enter Name :")
d = input("Enter Department :")
s = int(input("Enter Salary :"))
query="insert into employee values({},'{}','{}',{})".format(e,n,d,s)
cr.execute(query)
cn.commit()
print("A RECORD INSERTED...")
elif choice == 2: #UPDATING A RECORD
eno=int(input("Enter employee number to be updated "))
sal=int(input("Enter salary to be updated "))
query="update employee set salary={} where empno={}".format(sal,eno)
cr.execute(query)
print("A Record Updated ")
cn.commit()
elif choice == 3: #DELETING A RECORD
eno=int(input("Enter employee number to be deleted"))
query="delete from employee where empno={}".format(eno)
cr.execute(query)
print("Record(s) Deleted ")
cn.commit()
elif choice == 4: #SEARCHING A RECORD
eno=int(input("Enter employee number to be searched"))
query="select * from employee where empno={}".format(eno)
cr.execute(query)
result = cr.fetchall()
if cr.rowcount==0:
print("Record not found")
else:
print("EMPNO","NAME","DEPARTMENT","SALARY")
for row in result:
print(row[0],row[1],row[2],row[3])
cn.commit()
elif choice == 5: #DISPLAYING RECORDS
query="select * from employee"
cr.execute(query)
result = cr.fetchall()
print("EMPNO","NAME","DEPARTMENT","SALARY")
for row in result:
print(row[0],row[1],row[2],row[3])
cn.commit()
elif choice==6: #CLOSING DATABASE
cn.close()
print("File closed successfully...")
break
else:
print("Invalid Choice...")
choice=int(input("1. ADD RECORD 2. UPDATE RECORD 3.DELETE RECORD 4. SEARCH 5.DISPLAY 6.EXIT : "))
