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

Class-12 Practical Program

Uploaded by

Ricky Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Class-12 Practical Program

Uploaded by

Ricky Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Program 1: Program to read and display file content line by line with

each word separated by „#‟

f = open("file1.txt") for

line in f:
words = line.split()
for w in words:
print(w+'#',end='')
print()
f.close()

NOTE : if the original content of file is:


India is my country I
love python
Python learning is fun

OUTPUT
India#is#my#country#
I#love#python# Python#learning#is#fun#
Program 2: Program to read the content of file and display the total
number of consonants, uppercase, vowels and lower case characters‟

f = open("file1.txt")
v=0
c=0
u=0
l=0
o=0
data = f.read()
vowels=['a','e','i','o','u']
for ch in data:
if ch.isalpha():
if ch.lower() in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
elif ch!=' ' and ch!='\n': o+=1
print("Total Vowels in file :",v)
print("Total Consonants in file n :",c)
print("Total Capital letters in file :",u)
print("Total Small letters in file :",l)
print("Total Other than letters :",o)
f.close()

NOTE : if the original content of file is:


India is my country I
love python
Python learning is fun 123@

OUTPUT
Total Vowels in file : 16
Total Consonants in file : 30
Total Capital letters in file :2
Total Small letters in file : 44
Total Other than letters :4
Program 3: Program to create binary file to store Rollno and Name, Search
any Rollno and display name if Rollno found otherwise “Rollno not found”

Import pickle
student=[ ]
f=open('student.dat','wb') ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb')
student=[ ]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'

while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
OUTPUT
Enter Roll Number :1
Enter Name :Amit

Add More ?(Y)y

Enter Roll Number :2


Enter Name :Jasbir

Add More ?(Y)y

Enter Roll Number :3


Enter Name :Vikral
Add More ?(Y)n

Enter Roll number to search :2 ##


Name is : Jasbir ##
Search more ?(Y) :y

Enter Roll number to search :1 ##


Name is : Amit ##
Search more ?(Y) :y

Enter Roll number to search :4 ####Sorry!


Roll number not found #### Search more ?(Y) :n
Program 4: Program to read the content of file line by line and write it
to another file except for the lines contains „a‟ letter in it.

#Program to read line from file and wrrite it to another line letter 'a'
#Except for those line which contains

f1 = open("file2.txt")
f2 = open("file2copy.txt","w")

for line in f1:


if 'a' not in line:
f2.write(line)
print(“## File Copied Successfully! ##”)
f1.close()
f2.close()

NOTE: Content of file2.txt


a quick brown
fox one two
three four five
six seven
India is my country
eight nine ten
bye!

OUTPUT

## File Copied Successfully! ##

NOTE: After copy content of file2c opy.txt


one two three
four five six
seven eight
nine ten bye!
Program 5: Program to create CSV file and store empno,name,salary
and search any empno and display name,salary and if not found
appropriate message.

import csv
with open('myfile.csv',mode='a') as csvfile:
mywriter = csv.writer(csvfile,delimiter=',')
ans='y'
while ans.lower()=='y':
eno=int(input("Enter Employee Number "))
name=input("Enter Employee Name ")
salary=int(input("Enter Employee Salary :"))
mywriter.writerow([eno,name,salary])
print("## Data Saved... ##")
ans=input("Add More ?")
ans='y'
with open('myfile.csv',mode='r') as csvfile:
myreader = csv.reader(csvfile,delimiter=',')
while ans=='y':
found=False
e = int(input("Enter Employee Number to search :"))
for row in myreader:
if len(row)!=0:
if int(row[0])==e:
print("============================")
print("NAME :",row[1])
print("SALARY :",row[2])
found=True
break
if not found:
print("==========================")
print(" EMPNO NOT FOUND")
print("==========================")
ans = input("Search More ? (Y)")
OUTPUT:-

Enter Employee Number 1

Enter Employee Name Amit

Enter Employee Salary :90000 ##

Data Saved... ##

Add More ?y

Enter Employee Number 2

Enter Employee Name Sunil

Enter Employee Salary :80000 ##

Data Saved... ##

Add More ?y

Enter Employee Number 3

Enter Employee Name Satya

Enter Employee Salary :75000 ##

Data Saved... ##

Add More ?n

Enter Employee Number to search :2

============================

NAME : Sunil

SALARY : 80000

Search More ? (Y)y

Enter Employee Number to search :3

============================

NAME : Satya

SALARY : 75000

Search More ? (Y)y

Enter Employee Number to search :4

========================== EMPNO
NOT FOUND

==========================

Search More ? (Y)n


Program 6: Program to implement Stack in Python using List

def isEmpty(S):
if len(S)==0:
return True
else:
return False

def Push(S,item):
S.append(item)
top=len(S)-1

def Pop(S):
if isEmpty(S):
return "Underflow"
else:
val = S.pop()
if len(S)==0:
top=None
else:
top=len(S)-1
return val

def Peek(S):
if isEmpty(S):
return "Underflow"
else:
top=len(S)-1
return S[top]

def Show(S):
if isEmpty(S):
print("Sorry No items in Stack ")
else:
t = len(S)-1
print("(Top)",end='')
while(t>=0):
print(S[t],"<==",end=' ')
t-=1
print( )
# main begins here
S=[] #Stack
top=None
while True:
print("**** STACK DEMONSTRATION ******")
print("1. PUSH ")
print("2. POP")
print("3. PEEK")
print("4. SHOW STACK ")
print("0. EXIT")
ch = int(input("Enter your choice :"))
if ch==1:
val = int(input("Enter Item to Push :"))
Push(S,val)
elif ch==2:
val = Pop(S)
if val=="Underflow": print("Stack is
Empty")
else:
print("\nDeleted Item was :",val)
elif ch==3:
val = Peek(S)
if val=="Underflow":
print("Stack Empty")
else:
print("Top Item :",val)
elif ch==4:
Show(S)
elif ch==0:
print("Bye")
break

OUTPUT
**** STACK DEMONSTRATION ******
1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :1 Enter
Item to Push :10

Cont…
**** STACK DEMONSTRATION ******
1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :1 Enter
Item to Push :20

**** STACK DEMONSTRATION ******


1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :1
Enter Item to Push :30

**** STACK DEMONSTRATION ******


1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :4
(Top) 30 <== 20 <== 10 <==

**** STACK DEMONSTRATION ******


1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :3 Top
Item : 30

**** STACK DEMONSTRATION ******


1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :2 Deleted

Item was : 30
**** STACK DEMONSTRATION ******
1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :4 (Top) 20
<== 10 <==

**** STACK DEMONSTRATION ******


1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :0 Bye
Program 7: Program to take 10 sample phishing email, and find the most common
word occurring

#Program to take 10 sample phishing


#and count the most commonly uring word
occ
Phishing email=[
"[email protected]",
"[email protected]
"[email protected]",
"[email protected] ,
"[email protected]",
"[email protected]"
"[email protected]"
"luckyjackpot@americanlotter
"[email protected]
"[email protected]"]

myd={}
for e in phishing email:
x=e.split('@')
for w in x:
if w not in myd:
myd[w]=1
else:
myd[w]+=1
key_max = max(myd,key=myd.get)
print("Most Common Occuring word is :",key_max)

OUTPUT

Most Common Occuring word is : mymoney.com

8 Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii) which are based on tables
TABLE: TRANSACT
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2017-06-01
T003 102 2000 Withdraw2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 102 12000 Deposit 2017-11-06

(i) To display details of all transactions of TYPE Withdraw from TRANSACT


table
(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in
month of
„May‟ 2017 from table TRANSACT
(iii) To display first date of transaction (DOT) from table TRANSACT for
Account having ANO as 102
(iv) To display ANO, ANAME, AMOUNT and DOT of those persons from
ACCOUNT and TRANSACT table who have done transaction less
than or equal to 3000
(v) SELECT ANO, ANAME FROM ACCOUNT
WHERE ADDRESS NOT IN ('CHENNAI', 'BANGALORE');
(vi) SELECT DISTINCT ANO FROM TRANSACT
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM
TRANSACT GROUP BY ANO HAVING COUNT(*)> 1
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT
WHERE DOT <= '2017-10-01'
Ans. (i) Select * from TRANSACT where TYPE=’Withdraw’;
(ii) Select ANO, AMOUNT from TRANSACT where DOT like ‘%-05-%’;
(iii) Select MIN(DOT) from TRANSACT where ANO=102
(iv) Select ANO,T.ANO,ANAME,AMOUNT from ACCOUNT A, TRANSACT T where A.ANO = T.ANO and
AMOUNT<=3000;
(v)
ANO ANAME

103 Ali Reza


105 Simran Kaur
(vi)
ANO

101
103
102
(vii)

(viii)
9 Consider the following tables EMP and SALGRADE, write the query for (i) to (vi)
and output
for (vii) to (x)

TABLE: EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Vikrant Executive S03 2003-03-23 1980-01-13
102 Ravi Head-IT S02 2010-02-12 1987-07-22
103 John Cena Receptionist S03 2009-06-24 1983-02-24
105 Azhar Ansari GM S02 2009-08-11 1984-03-03
108 Priyam Sen CEO S01 2004-12-29 1982-01-19

TABLE: SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000

(i) To display details of all employee in descending order of their DOJ


(ii) To display NAME AND DESIG of those employees whose sgrade is either
„S02‟ or
„S03‟
(iii) To display NAME, DESIG, SGRADE of those employee who joined in the
year 2009
(iv) To display all SGRADE, ANNUAL_SALARY from table SALGRADE [where
ANNUAL_SALARY = SALARY*12]
(v) To display number of employee working in each SALGRADE from table
EMPLOYEE
(vi) To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and SALGRADE
where SALARY is less than 50000
(vii) Select MIN(DOJ), MAX(DOB) from employee;
(viii) Select SGrade,Salary+HRA from SalGrade where Sgrade=‟S02‟
(ix) Select count(distinct sgrade) from employee
(x) Select sum(salary), avg(salary) from salgrade
A (i) SELECT * FROM EMPLOYEE ORDER BY DOJ DESC
n (ii) SELECT NAME,DESIG FROM EMPLOYEE WHERE SGRADE IN ('S02','S03')
s
OR
SELECT NAME,DESIG FROM EMPLOYEE WHERE SGRADE='S02' OR
SGRADE='S03'
(iii) SELECT NAME,DESIG,SGRADE FROM EMPLOYEE WHERE DOJ LIKE '2009%'
(iv) SELECT SGRADE,SALARY*12 ANNUAL_SALARY FROM SALGRADE
(v) SELECT SGRADE,COUNT(*) FROM EMPLOYEE GROUP BY SGRADE
(vi) SELECT NAME,DESIG,SALARY,HRA FROM EMPLOYEE E,SALGRADE S WHERE
E.SGRADE=S.SGRADE AND SALARY<=50000
(vii) MIN(DOJ) MAX(DOB)

2003-03-23 1987-07-22
(viii) SGRADE SALARY+HRA

S02 44000
(ix) COUNT(*)

3
(x) SUM(SALARY) AVG(SALARY)

112000 37333.33

10 a) In a database there are two tables : Write MYSQL queries for (i) to (iii)
Table : Item
ICode IName Price Color VCode
S001 Mobile Phones 30000 Silver P01
S002 Refrigerator 20000 Cherry P02
S003 TV 45000 Black P03
S004 Washing Machine 12000 White
P04 S005 Air Conditioner
50000 White P05
Table : Vendor
VCode VName
P01 Rahul
P02 Mukesh
P03 Rohan
P04 Kapil
(i) To display ICode, IName and VName of all the vendors, who manufacture
“Refrigerator”.
(ii) To display IName, ICode, VName and price of all the products whose price
>=23000
(iii) To display Vname and IName manufactured by vendor whose code is
“P04”.
Ans (i) Select ICode, IName,VName from Item I,Vendor V where
I.Vcode=V.VCode and IName='Refrigerator'
(ii) Select IName, ICode,VName from Item I,Vendor V where
I.Vcode=V.VCode and Price>=23000
(iii) Select VName,IName from Item I,Vendor V where I.Vcode=V.VCode
and
I.VCode='P04'

11 In a database there are two tables : Write MYSQL queries for


(i) to (vi) Table : Doctors
DocID DocName Department NoofOpdDays
101 J K Mishra Ortho 3
102 Mahesh tripathi ENT 4
103 Ravi Kumar Neuro 5
104 Mukesh Jain Physio 3
Table : Patients
PatNo PatName Department DocId
1 Payal ENT 102
2 Naveen Ortho 101
3 Rakesh Neuro 103
4 Atul Physio 104
(i) To display PatNo, PatName and corresponding DocName for each patient.
(ii) To display the list of all doctors whose NoofOpdDays are more than 3
(iii) To display DocName, Department,PatName and DocId from both the
tables where DocID is either 101 or 103
(iv) To display total no of different departments from Patients table.
Ans. (i) select PatNo,PatName,DocName from Doctors D,Patients P
where D.DocID =
P.DocID
(ii) select * from Doctors where NoofOpdDays>3
(iii) Select DocID,DocName,Department,PatName from Doctor D,
Patient P where D.DocId = P.DocId and DocId in (101,103)
(iv) select count(distinct Department) from Patient
Considering the Visitor table data, write the
queryVisitorID
for (i) to (iv)VisitorNam
and Gender ComingFromoutput for (v) to (viii)
AmountPai
e d
12 1 Suman F Kanpur 2500
2 Indu F Lucknow 3000
3 Rachana F Haryana 2000
4 Vikram M Kanpur 4000
5 Rajesh M Kanpur 3000
6 Suresh M Allahabad 3600
(i) 7 Dinesh M Lucknow
Write
8 Shikha F Varanasi 5000 a

query to display VisitorName, Coming From details of Female


Visitors with Amount Paid more than 3000
(ii) Write a query to display all coming from location uniquely
(iii) Write a query to insert the
following values- 7,
„Shilpa‟,‟F‟,‟Lucknow‟,3000
(iv) Write a query to display all details of visitors in order of their
AmountPaid from highest to lowest
(v) Select VisitorName from Visitor where Gender=‟M‟;
(vi) Select AmountPaid+200 from Visitor where VisitorID=6;
(vii) Select Sum(AmountPaid) from Visitor where comingFrom=‟Kanpur‟;
(viii) Select Count(VisitorName) from Visitor where AmountPaid is NULL;

Ans. (i) Select VisitorName,ComingFrom from where Gender=' and


Visitor F'
AmountPaid>3000
(ii) Select distinct ComingFrom from Visitor
(iii) insert into visitor
values(7,'Shilpa','F','Lucknow',3000)
(iv) Select * from visitor order by AmountPaid
desc
(v) VisitorName

Vikram
Rajesh
Suresh
Dinesh
(vi) AmountPaid+200

3800
(vii) Sum(AmountPaid)

9500
(viii) Count(VisitorName)

1
Program 13: Program to connect with database and store record of
employee and display records.

import mysql.connector as mycon

con =
mycon.connect(host='127.0.0.1',user='root',password="admin")

cur = con.cursor()
cur.execute("create database if not exists
company") cur.execute("use company")
cur.execute("create table if not exists employee(empno int, name varchar(20), dept
varchar(20),salary int)")
con.commit()
choice=None
while choice!
=0:
print("1. ADD RECORD ")
print("2. DISPLAY RECORD ")
print("0. EXIT")
choice = int(input("Enter Choice
:"))
if choice == 1:
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)
cur.execute(query)
con.commit()
print("## Data Saved
##")
elif
choice == 2:
query="select * from employee"
cur.execute(query)
result = cur.fetchall()
print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[
3])
elif
choice==0:
con.close() print("## Bye!!
##")
else:
print("## INVALID CHOICE ##")

OUTPUT

1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :1
Enter Employee Number :1
Enter Name :AMIT
Enter Department :SALES
Enter Salary :9000
## Data Saved ##
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :1
Enter Employee Number :2
Enter Name :NITIN
Enter Department :IT
Enter Salary :80000 ##
Data Saved ##
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :2
EMPNO NAME DEPARTMENT SALARY
1 AMIT SALES 9000
2 NITIN IT 80000
1. ADD RECORD
2. DISPLAY RECORD
0. EXIT
Enter Choice :0 ##
Bye!! ##
Program 14: Program to connect with database and search employee
number in table employee and display record, if empno not found display
appropriate message.

import mysql.connector as mycon


con = mycon.connect(host='127.0.0.1',user='root',password="admin", database="company")
cur = con.cursor() print("#"*40)
print("EMPLOYEE SEARCHING FORM")
print("#"*40)
print("\n\n") ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO SEARCH :"))
query="select * from employee where empno={}".format(eno) cur.execute(query)
result = cur.fetchall() if
cur.rowcount==0:
print("Sorry! Empno not found ")
else:
print("%10s"%"EMPNO", "%20s"%"NAME","%15s"%"DEPARTMENT", "%10s"%"SALARY")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])

ans=input("SEARCH MORE (Y) :")

OUTPUT

######################################## EMPLOYEE
SEARCHING FORM ########################################

ENTER EMPNO TO SEARCH :1


EMPNO NAME DEPARTMENT SALARY
1 AMIT SALES 9000
SEARCH MORE (Y) :y
ENTER EMPNO TO SEARCH :2
EMPNO NAME DEPARTMENT SALARY
2 NITIN IT 80000
SEARCH MORE (Y) :y
ENTER EMPNO TO SEARCH :4
Sorry! Empno not found SEARCH
MORE (Y) :n
Program 15: Program to connect with database and update the employee
record of entered empno.
import mysql.connector as mycon
con = mycon.connect(host='127.0.0.1',user='root',password="admin", database="company")
cur = con.cursor() print("#"*40)
print("EMPLOYEE UPDATION FORM")
print("#"*40)
print("\n\n") ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO UPDATE :"))
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
if cur.rowcount==0:
print("Sorry! Empno not found ")
else:
print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3]) choice=input("\
n## ARE YOUR SURE TO UPDATE ? (Y) :")
if choice.lower()=='y':
print("== YOU CAN UPDATE ONLY DEPT AND SALARY ==")
print("== FOR EMPNO AND NAME CONTACT ADMIN ==")
d = input("ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT
TO CHANGE
)") if d=="":
d=row[2]
try:
s = int(input("ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE )
"))
except:
s=row[3]
query="update employee set dept='{}',salary={} where empno={}".format(d,s,eno)
cur.execute(query) con.commit()
print("## RECORD UPDATED ## ")
ans=input("UPDATE MORE (Y) :")

OUTPUT

######################################## EMPLOYEE
UPDATION FORM ########################################

ENTER EMPNO TO UPDATE :2


EMPNO NAME DEPARTMENT SALARY
2 NITIN IT 90000
## ARE YOUR SURE TO UPDATE ? (Y) :y
== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO CHANGE ) ENTER NEW SALARY,(LEAVE
BLANK IF NOT WANT TO CHANGE )
## RECORD UPDATED ##
UPDATE MORE (Y) :y

ENTER EMPNO TO UPDATE :2


EMPNO NAME DEPARTMENT SALARY
2 NITIN IT 90000

## ARE YOUR SURE TO UPDATE ? (Y) :y


== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO CHANGE )SALES
ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE )
## RECORD UPDATED ##
UPDATE MORE (Y) :Y

ENTER EMPNO TO UPDATE :2


EMPNO NAME DEPARTMENT SALARY
2 NITIN SALES 90000

## ARE YOUR SURE TO UPDATE ? (Y) :Y


== YOU CAN UPDATE ONLY DEPT AND SALARY ==
== FOR EMPNO AND NAME CONTACT ADMIN ==
ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO CHANGE )
ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE ) 91000 ##
RECORD UPDATED ##
UPDATE MORE (Y) :Y

ENTER EMPNO TO UPDATE :2


EMPNO NAME DEPARTMENT SALARY
2 NITIN SALES 91000

## ARE YOUR SURE TO UPDATE ? (Y) :N


UPDATE MORE (Y) :N
Program 1 6: Program to connect with database and delete the record of
entered employee number.

import mysql.connector as mycon


con = mycon.connect(host='127.0.0.1',user='root',password="admin",
database="company")
cur = con.cursor()
print("#"*40)
print("EMPLOYEE DELETION FORM")
print("#"*40)
print("\n\n") ans='y'
while ans.lower()=='y':
eno = int(input("ENTER EMPNO TO DELETE :"))
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
if cur.rowcount==0:
print("Sorry! Empno not found ")
else:
print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT",
"%10s"%"SALARY")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
choice=input("\n## ARE YOUR SURE TO DELETE ? (Y) :")
if choice.lower()=='y':
query="delete from employee where empno={}".format(eno)
cur.execute(query)
con.commit()
print("=== RECORD DELETED SUCCESSFULLY! ===")
ans=input("DELETE MORE ? (Y) :")

OUTPUT

###############################
######### EMPLOYEE DELETION FORM
###############################
#########

ENTER EMPNO TO DELETE :2


EMPNO NAME DEPARTMENT SALARY
2 NITIN SALES 91000

## ARE YOUR SURE TO DELETE ? (Y) :y


=== RECORD DELETED SUCCESSFULLY! === DELETE MORE ? (Y) :y
ENTER EMPNO TO DELETE :2
Sorry! Empno not found DELETE
MORE ? (Y) :n

You might also like