0% found this document useful (0 votes)
3 views36 pages

Practical File

This document is a practical file for the academic year 2025-2026, submitted by student Bhavika Negi under the guidance of Mr. Shivam Sharma. It includes a collection of Python programs and SQL queries, totaling 21 practicals, aimed at fulfilling the Computer Science practical evaluation requirements of CBSE. The content covers various programming tasks, including mathematical computations, string manipulations, file handling, and database connectivity.

Uploaded by

Tarun Rwt Singh
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)
3 views36 pages

Practical File

This document is a practical file for the academic year 2025-2026, submitted by student Bhavika Negi under the guidance of Mr. Shivam Sharma. It includes a collection of Python programs and SQL queries, totaling 21 practicals, aimed at fulfilling the Computer Science practical evaluation requirements of CBSE. The content covers various programming tasks, including mathematical computations, string manipulations, file handling, and database connectivity.

Uploaded by

Tarun Rwt Singh
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/ 36

AVN SCHOOL, KOTDWAR

ACADEMIC YEAR: 2025-2026

A
Practical File
of
Python Program and SQL Queries

Submitted By: - Guided By: -

Name: - BHAVIKA NEGI MR. SHIVAM SHARMA


Class: - XII (PCM) PGT(CS)
Roll No.:-
AVN SCHOOL, KOTDWAR

CERTIFICATE

This is to certify that BHAVIKA NEGI student of Class XII, AVN SCHOOL
HALDUKHATA KOTDWAR has completed the PRACTICAL FILE during the
academic year 2025-26 towards partial fulfillment of credit for the Computer
Science practical evaluation of CBSE and submitted satisfactory report, as
compiled in the following pages, under my supervision.
Total number of practical certified are: 21

Internal Examiner External Examiner


Signature Signature
TABLE OF CONTENTS [ T O C ]

S.No Page
Practical
. No

Python Programs
01 WAP to compute x n of given two integers x and n.
02 WAP to accept a number from the user and calculate factorial of a number.

03 WAP to accept any number from user and check it is Prime no. or not.

04 WAP to accept a string and display whether it is a palindrome.


WAP that counts the number of alphabets and digits, uppercase letters, lowercase letter,
05 spaces and other characters in the string entered.

06 WAP to remove all odd numbers from the given list.


07 WAP to display frequencies of all the elements of a list.
Write a Python program to input names of ‘n’ countries and their capital and currency,
08 store it in a dictionary and display in tabular form. Also search and display for a
particular country.
09 Write a Python Program to search any word in given string/sentence.
Write a Python Program to read and display file content line by line with each word
10 separated by “#‟.
Write a Python Program to create binary file to store Rollno, Name and Marks and
11 update marks of entered Rollno.
Write a Python Program to create CSV file and store empno, name, salary and search any
12 empno and display name, salary and if not found appropriate message.

13 Write a Python Program to implement Stack in Python using List.

14 Write a Python Program to implement Queue in Python using List.


SQL Queries
15 SQL commands based on table “GAMES”.
16 SQL queries and outputs for SQL queries based on tables “COMPANY” and
“CUSTOMER”.
17 SQL queries and outputs for SQL queries based on tables “SHOP” and
“ACCESSORIES”.
Python - SQL Connectivity Programs
18 Program to connect with database and store record of employee and display records.
19 Program to connect with database and search employee number in table employee and
display record, if empno not found display appropriate message.
20 Program to connect with database and update the employee record of entered empno.
21 Program to connect with database and delete the record of entered employee number.

n
Program -1 WAP to compute x of given two integers x and n.
Code:

x=int (input(“Enter a number”))


n=int (input(“Enter power”))
z=(x**n)
print(z)

********Output of the program****

Enter a number 2
Enter power 3
8

Program 2: WAP to accept a number from the user and calculate


factorial of a number.
Code:

num = int(input("Enter any number :"))


fact = 1
n = num # storing num in n for
printing
while num>=1: # loop to iterate from n to 1
fact = fact * num
num-=1

print("Factorial of ", n , " is :",fact)

*******Output of the program********

Enter any number :6


Factorial of 6 is : 720
Program 3: WAP to accept any number from user and check it is
Prime no. or not.

Code:
import math
num = int(input("Enter any number :"))
isPrime=True
for i in range(2,int(math.sqrt(num))+1):
if num % i == 0:
isPrime=False
if isPrime:
print("## Number is Prime ##")
else:
print("## Number is not Prime ##")
********Output of the program********

Enter any number :12


## Number is not Prime ##
>>>
Enter any number :13
## Number is Prime ##
>>>
Program 4: WAP to accept a string and display whether it is a
palindrome.

Code:

********Output of the program********


Program 5- WAP to read the content of file and display the total
number of consonants, uppercase, vowels and lower case
characters.

Code:

********Output of the program********


Program 6: WAP to remove all odd numbers from the given list.

Code:

********Output of the program********


Program 7: WAP to display frequencies of all the elements of a
list.

Code:

********Output of the program********


Program 8: Write a Python program to input names of ‘n’
countries and their capital and currency, store it in a dictionary
and display in tabular form. Also search and display for a
particular country.

Code:
Program 9: Write a Python Program to search any word in given
string /sentence.

Code:

def countWord(str1,word):
s = str1.split()
count=0
for w in s:
if w==word:
count+=1
return count
str1 = input("Enter any sentence :")
word = input("Enter word to search in sentence :")
count = countWord(str1,word)
if count==0:
print("## Sorry! ",word," not present ")
else:
print("## ",word," occurs ",count," times ## ")

********Output of the program********


Enter any sentence :my computer your computer our computer
everyones computer
Enter word to search in sentence :computer
## computer occurs 4 times ##

Enter any sentence :learning python is fun


Enter word to search in sentence :java
## Sorry! java not present
Program 10: Write a Python Program to read and display file
content line by line with each word separated by “#‟.

Code:
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 of the program********

India#is#my#country#
I#love#python#
Python#learning#is#fun#
Program 11: Write a Python Program to create binary file to store
Rollno, Name and Marks and update marks of entered Rollno.
Code:
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
marks = int(input("Enter Marks :")) student.append([roll,name,marks])
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 update :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
print("## Current Marks is :",s[2]," ##")
m = int(input("Enter new marks :"))
s[2]=m
print("## Record Updated ##")
found=True
break

if not found:
print("####Sorry! Roll number not found ####")
ans=input("Update more ?(Y) :")
f.close()
********Output of the program********

Enter Roll Number :1


Enter Name :Amit
Enter Marks :99
Add More ?(Y)y

Enter Roll Number :2


Enter Name :Vikrant
Enter Marks :88
Add More ?(Y)y

Enter Roll Number :3


Enter Name :Nitin
Enter Marks :66
Add More ?(Y)n

Enter Roll number to update :2


## Name is : Vikrant ##
## Current Marks is : 88 ##
Enter new marks :90
## Record Updated
## Update more ?(Y) :n
Program 12: Write a Python Program to create CSV file and store
empno, name, salary and search any empno and display name,
salary and if not found appropriate message.

Code:
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 of the program********
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 13: Write a Python Program to implement Stack in
Python using List.
Code:
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 of the program********
**** STACK DEMONSTRATION ******
1. PUSH
2. POP
3. PEEK
4. SHOW STACK
0. EXIT
Enter your choice :1
Enter Item to Push :10
**** 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 14: Write a Python Program to implement Queue in Python u
List.
Code:
def isEmpty(Q):
if len(Q)==0:
return True
else:
return False
def
Enque
ue(Q,it
em):
Q.appe
nd(ite
m) if
len(Q)
==1:
front=rear=0
else:
rear=len(Q)-1
def Dequeue(Q):
if isEmpty(Q):
return "Underflow"
else:
val = Q.pop(0)
if len(Q)==0:
front=re
ar=None
return val
def Peek(Q):
if isEmpty(Q):
return "Underflow"
else:
front=0
return Q[front]
def Show(Q):
if isEmpty(Q):
print("Sorry No items in Queue ")
else:
t = len(Q)-1
print("(Front)",end=' ')
front = 0
i=front
rear = len(Q)-1
while(i<=rear):
print(Q[i],"==>",end=' ')
i+=1
print()
Q=[] #Queue front=rear=None while True:
print("**** QUEUE DEMONSTRATION ******")
print("1. ENQUEUE ")
print("2. DEQUEUE")
print("3. PEEK")
print("4. SHOW QUEUE ")
print("0. EXIT")
ch = int(input("Enter your
choice :"))
if ch==1:
val = int(input("Enter Item to
Insert :")) Enqueue(Q,val)
elif ch==2:
val = Dequeue(Q)
if val=="Underflow":
print("Queue is
Empty")
else:
print("\nDeleted Item was :",val)
elif ch==3:
val = Peek(Q)
if
val=="Under
flow":
print("Queue
Empty")
else:
print("Front Item :",val)
elif ch==4:
Show(Q)
elif ch==0:
print("Bye")
break

********Output of the program********


**** QUEUE DEMONSTRATION ******
0. ENQUEUE
1. DEQUEUE
2. PEEK
3. SHOW QUEUE
0. EXIT
Enter your
choice :1 Enter
Item to Insert
:10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :1
Enter Item to Insert :20
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :1 Enter
Item to Insert
:30
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :4
(Front) 10 ==> 20 ==> 30 ==>
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :3
Front Item
: 10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :2
Deleted Item
was : 10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :4
(Front) 20
==> 30 ==>
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :0
Bye
Program 15:

(i) To display the name of all GAMES with their GCode.


(ii) To display details of those GAMES which are having PrizeMoney more
than 7000.
(iii) To display the content of the GAMES table in ascending order of
ScheduleDate.
(iv) To display sum of PrizeMoney for each Type of GAMES.

Solution:
(i). Select GameName, GCode from GAMES;
(ii). Select * from GAMES where PeizeMoney > 7000;
(iii). Select * from GAMES order by ScheduleDate;
(iv). Select sum(PeizeMoney), Type from GAMES group by Type;
Program 16: Write SQL queries for (i) to (iv) and find outputs for SQL
queries (v) to (viii),
which are based on the tables “COMPANY” and
“CUSTOMER”.

I. To display those company name which are having prize less than 30000.
II. To display the name of the companies in reverse alphabetical order.
III. To increase the prize by 1000 for those customer whose name starts with S?
IV. To add one more column totalprice with decimal( 10,2) to the table customer
V. SELECT COUNT(*) , CITY FROM COMPANY GROUP BY CITY;
VI. SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10;
VII. SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;
VIII. SELECT PRODUCTNAME,CITY, PRICE FROM COMPANY, CUSTOMER WHERE
COMPANY. CID=CUSTOMER.CID AND PRODUCTNAME=”MOBILE”;

Solution:

I. SELECT NAME FROM COMPANY WHERE COMPANY.CID=CUSTOMER .CID AND


PRICE < 30000;
II. SELECT NAME FROM COMPANY ORDER BY NAME DESC;
III. UPDATE CUSTOMER SET PRICE = PRICE + 1000 WHERE NAME LIKE ‘S%’;
IV. ALTER TABLE CUSTOMER ADD TOTALPRICE DECIMAL(10,2);

V. VI. 50000, 70000 VII. 13.33 VIII.


Program 17: Write SQL queries for (i) to (iv) and find outputs for SQL
queries (v) to (viii),
which are based on the tables “SHOP” and
“ACCESSORIES”.

I. To display Name and Price of all the Accessories in ascending order of their Price.
II. To display Id and SName of all Shop located in Nehru Place.
III. To display Minimum and Maximum Price of each Name of Accessories.
IV. To display Name, Price of all Accessories and their respective SName where they are available.
V. SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE> =5000;
VI. SELECT AREA, COUNT(*) FROM SHOP GROUP BY AREA;
VII. SELECT COUNT (DISTINCT AREA) FROM SHOP;
VIII. SELECT NAME, PRICE*0.05 as DISCOUNT FROM ACCESSORIES WHERE ID IN (‘SO2‘,’SO3‘);

Solution:

I. SELECT Name, Price FROM ACCESSORIES ORDER BY Price;


II. SELECT ID SName FROM SHOP WHERE Area=”Nehru Place”;
III. SELECT Name, max (Price); min(Price) FROM ACCESSORIES, Group By Name;
IV. SELECT Name,price, Sname FROM
ACCESSORIES, SHOP WHERE SHOE .ID=ACCESSORIES .ID;

V. VI.

VII. VIII.
Program 18: Program to connect with database and store record of
employee and display
records.
Code:
import mysql.connector as mycon
con = mycon.connect(host="localhost",user="root",password="",database="company")
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 of the program********
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 19: Program to connect with database and search
employee number in table
employee and display record, if empno not found
display appropriate message.

Code:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="", 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 of the program********


######################################## 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 20: Program to connect with database and update the


employee record of entered
empno.
Code:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="", 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 ## ")

********Output of the program********


########################################
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 21: Program to connect with database and delete the


record of entered employee
number.
Code:
import mysql.connector as mycon
con = mycon.connect(host='localhost',user='root',password="", 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 of the program********


########################################
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