0% found this document useful (0 votes)
19 views44 pages

Class 12-CS Practical File 2023 Sample 1

This document is a practical file for a Computer Science project by a student named Shubh Narayan from Kendriya Vidyalaya, Janakpuri for the academic year 2023-24. It includes a detailed index of various programming assignments and practical tasks, primarily written in Python, covering topics such as list manipulation, string processing, file handling, and SQL commands. Each practical section outlines the aim, software used, input, and expected output for the respective programming tasks.

Uploaded by

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

Class 12-CS Practical File 2023 Sample 1

This document is a practical file for a Computer Science project by a student named Shubh Narayan from Kendriya Vidyalaya, Janakpuri for the academic year 2023-24. It includes a detailed index of various programming assignments and practical tasks, primarily written in Python, covering topics such as list manipulation, string processing, file handling, and SQL commands. Each practical section outlines the aim, software used, input, and expected output for the respective programming tasks.

Uploaded by

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

PM SHRI

KENDRIYA VIDYALAYA, JANAKPURI

ACADEMIC YEAR : 2023-24


PRACTICAL FILE

NAME : SHUBH NARAYAN

ROLL NUMBER :

CLASS : XII-A

SUBJECT : COMPUTER SCIENCE

SUBJECT CODE : 083

PROJECT GUIDE : Mr. RANJEET


PGT COMPUTER SCIENCE
KENDRIYA VIDYALAYA, JANAKPURI
NEW DELHI
INDEX

S. AIM/PRACTICAL DATE SIGN


no

1. WAP to input a list and find the minimum and maximum 19/04/2023
value along with its position

2. WAP to input a list and store the positive and negative 19/04/2023
number from the list in two separate lists and print the same.

3. WAP to count and display the number of vowels, 19/04/2023


consonants, uppercase and lowercase characters in a string

4. WAP to check whether a number is a perfect number, an 27/04/2023


armstrong number or a palindrome in a single program

5. WAP to input a string and check whether it is a palindrome 27/04/2023


string or not

6. Write a menu driven program in python to display Fibonacci 27/04/2023


series of a given no and print factorial of a given no

7. Program to search any word in given string 27/04/2023

8. Program to read the content of file and display the total 08/07/2023
number of consonants, uppercase, vowels , lowercase and
digits characters

9. Program to read and display file content line by line with 08/07/2023
each word separated by #.

10. Program to read the content of file line by line and write it to 08/07/2023
another file except for the lines which contains “a” letter in i

11. Consider a dictionary with keys as course name and fee as 21/07/2023
value. Write a program to push the course name in stack
where the fee is more than 10000. Pop and display the
contents of stack on the screen.
S.NO AIM/PRACTICAL DATE SIGN

12. Write a program to pass an integer list as stack to a 21/07/2023


function and push only those elements in the stack which
are divisible by 7. Also write a function to pop and display
the stack.

13. Program to create binary file to store Rollno and Name, 21/07/2023
Search any Rollno and display name if Rollno found
otherwise “Rollno not found”

14. Program to create binary file to store Rollno,Name and 18/08/2023


Marks and update marks of entered Rollno

15. Program to create CSV file and store empno,name,salary 18/08/2023


and search any empno and display name,salary and if not
found appropriate message.

16. Program to generate random number 1-6, simulating a 18/08/2023


dice

17. Write brief detail about SQL and its commands 06/10/2023

18. Write the SQL command/query based on Creation, 06/10/2023


Insertion, Deletion & Pattern Matching

19. Write the SQL command/query based on Alter, Update, 06/10/2023


Deletion and Sorting

20. Write the SQL command/query based on Aggregate 26/10/2023


Functions

21. Write the SQL command/query based on Group by and 26/10/2023


having clause

22. Write the SQL command/query based on Single Row 26/10/2023


functions.

23. Write the SQL command/query based on Joins 16/11/2023


(Cartesian/Equi/Natural)

24. Program to connect with database and store record of 16/11/2023


employee and display records.

25. Program to connect with database and search employee 16/11/2023


number in table employee and display record, if empno not
found display appropriate message.
26. Program to connect with database and update the 17/11/2023
employee record of entered empno.

27. Program to connect with database and delete the record of 17/11/2023
entered employee number
19/04/2023

𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 1

AIM: WAP to input a list and find the minimum and maximum value along
with its position

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:

L=eval(input(“enter the list:”))


max=L[0]
min=L[0]
pos_max=0
pos_min=0
for i in range(0,len(L)):
if L[i] > max:
max=L[i]
pos_max=i
if L[i] < min:
min=L[i]
pos_min=i
print(“The maximum value of list is ”, max ,”and is at index”, pos_max)
print(“The minimum value of list is ”, min ,”and is at index”, pos_min)

OUTPUT:

______________________________________________________
19/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 2

AIM: WAP to input a list and store the positive and negative number from the
list in two separate lists and print the same.

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:

L=eval(input("enter the list :"))


pos=[]
neg=[]
for i in L:
if i>0:
pos.append(i)
if i<0:
neg.append(i)
print("the list of positive integer :", pos)
print("the list of negative integer :", neg

OUTPUT:

______________________________________________________
19/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 3

AIM: WAP to count and display the number of vowels, consonants uppercase
. and lowercase characters in a string.

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
STR=input("enter a string")
Ucase=Lcase=0
Vcount=Ccount=0
for i in STR:
if i in ["a","e","i","o","u","A","E","I","O","U"]:
Vcount += 1
else:
Ccount += 1
if i.isupper():
Ucase +=1
if i.islower():
Lcase += 1
print("the total number of vowel is:",Vcount)
print("the total number of consonants is:",Ccount)
print("the total number of uppercase letter is:",Ucase)
print("the total number of lowercase letter is:",Lcase)
OUTPUT:

______________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 4

AIM: WAP to check whether a number is a perfect number, an armstrong


. number or a palindrome in a single program

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
while True:
print("press 1: perfect number")
print("press 2: armstrong number")
print("press 3: palindrome number")
choice=int(input("enter the choice 1/2/3 : "))
if choice==1:
num=int(input("enter the number:"))
s=0
for i in range(1,num):
if num%i==0:
s=s+i
if s==num:
print(num,"is a perfect number")
else:
print(num,"is not a perfect number")
if choice==2:
num=int(input("enter the number:"))
s=0
temp=num
while temp!=0:
d=temp%10
s=s+d**3
temp=temp//10
if num==s:
print(num,"is a armstrong number")
else:
print(num,"is not a armstrong number")
if choice==3:
num=int(input("enter the number:"))
rev=0
temp=num
while temp!=0:
rem=temp%10
rev=rev*10+rem
temp=temp//10
if num==rev:
print(num,"is a palindrome")
else:
print(num,"is not a palindrome")
break

OUTPUT:

for perfect number :

for armstrong number :

for palindrome :

______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 5

AIM : WAP to input a string and check whether it is a palindrome string or not

SOFTWARE USED : IDLE (PYTHON 3.8 64-bit)

INPUT :
n=input("Enter a String:")
l=len(n)
mid=l//2
rev=-1
for i in range(0,mid):
if n[i]==n[rev]:
rev=rev-1
else:
print("String is not palindrome")
break
else:
print("String is Palindrome")

OUTPUT :
When string is a palindrome:

When string is not a palindrome:

______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 6

AIM : Write a menu driven program in python to display Fibonacci series of a


. given no and print factorial of a given no.

SOFTWARE USED : IDLE (PYTHON 3.8 64-bit)

INPUT :
while True:
print("press 1: for fibonacci series")
print("press 2: for the factorial of a number")
print("press 3: for exiting")
choice=int(input("Enter the choice"))
if choice==1:
num=int(input("Enter the number of element for the fibonacci series"))
num_1=0
num_2=1
print(num_1,end=" ")
print(num_2,end=" ")
for i in range(3,num+1):
num_3=num_1+num_2
print(num_3,end=" ")
num_1=num_2
num_2=num_3
print()
print("______________________________")
if choice==2:
num=int(input("Enter the number"))
temp=num
fac=1
while num>=1:
fac=fac*num
num=num-1
print("Factorial of",temp,"is",fac)
print("______________________________")
if choice==3:
for_exiting=input("do you wish to exit ?(y/n)")
if for_exiting in ["Y","y"]:
print("exiting the program")
break
else:
print("_____________________________")

OUTPUT:

______________________________________________________________
27/04/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 7

AIM : Program to search any word in given string/sentence.

SOFTWARE USED : IDLE (PYTHON 3.8 64-bit)

INPUT :
STRING=input("Enter the string/sentence:")
word=input("Enter the word to be searched in a string:")
lst=STRING.split( )
for i in range(0,len(lst)):
if lst[i]==word:
print("the word is found")

OUTPUT :

______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 8

AIM :Program to read the content of file and display the total number of
consonants, uppercase, vowels , lowercase and digits characters.

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT :
f=open("PR8.txt","r")
v_count=c_count=u_count=l_count=digit_count=0
a=f.read()
for i in a:
if i in "AEIOUaeiou":
v_count+=1
if i in "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz":
c_count+=1
if i.isupper():
u_count+=1
if i.islower():
l_count+=1
if i.isdigit():
digit_count+=1
print("the number of vowels in file is:",v_count)
print("the number of consonants in file is:",c_count)
print("the number of upper letters in file is:",u_count)
print("the number of lower letters in file is:",l_count)
print("the number of digits in file is:",digit_count)
f.close()

OUTPUT: FILE

______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 9
AIM : Program to read and display file content line by line with each word
separated by #.

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT :
f=open('myfile.txt','r')
for i in f:
words = i.split()
replaced= '#'.join(words)
print(replaced)

OUTPUT :

File:

______________________________________________________________
08/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 10

AIM:Program to read the content of file line by line and write it to another file
except for the lines which contains “a” letter in it

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
file_1=open("student.txt","r")
file_2=open("transfer.txt","w")
r=file_1.readlines()
flag=0
for i in r:
if i[0] != "a":
file_2.write(i)
flag=1
if flag==1:
print("write successful")
else:
print("no statement starts with a")
file_1.close()
file_2.close()

OUTPUT :

______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 11

AIM:Consider a dictionary with keys as course name and fee as value. Write
a program to push course name in stack where the fee is more than
10000. Pop and display contents of stack on the screen

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
dic={"chemistry":12000,"physic":7000,"biology":9500,"mathematics":15000}
stack=[]
for i in dic:
if dic[i]>10000:
stack.append(i)
while True:
if stack==[]:
print("the stack is empty")
break
else:
print(stack.pop())

OUTPUT:

______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 12

AIM: Write a program to pass an integer list as stack to a function and push
only those elements in the stack which are divisible by 7. Also write a
function to pop and display the stack

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
def Push():
for i in num_list:
if i%7==0:
stack.append(i)
def Pop():
while True:
if stack==[]:
print("stack is empty")
break
else:
print(stack.pop())
num_list=eval(input("Enter a list of number :"))
stack=[]
Push()
Pop()

OUTPUT:

______________________________________________________________
21/07/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 13

AIM: Program to create binary file to store Rollno and Name, Search any
Rollno and display name if Rollno found otherwise “Rollno not found”

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
import pickle
f1=open("student.dat","ab")
f2=open("student.dat","rb")
num=int(input("Enter the number of student whose data is to be entered :"))
for i in range(num):
roll=int(input("Enter the roll number of the student :"))
name=input("Enter the name of the student :")
record=[roll,name]
pickle.dump(record,f1)
f1.close()
search_roll=int(input("Enter the roll number of the student to be searched :"))
flag=0
while True:
try:
r=pickle.load(f2)
if r[0]==search_roll:
print("The name of the student is :",r[1])
flag=1
except EOFError:
break
if flag==0:
print("Roll number is not found")
f2.close()
OUTPUT:

file

______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 14
AIM: Program to create binary file to store Rollno,Name and Marks and
update marks of entered Rollno

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
import pickle
f1=open("marks.dat","ab")
f2=open("marks.dat","rb")
num=int(input("Enter the number of student whose data is to be entered :"))
for i in range(num):
roll=int(input("Enter the roll number of the student :"))
name=input("Enter the name of the student :")
marks=int(input("Enter the marks :"))
record=[roll,name,marks]
pickle.dump(record,f1)
f1.close()
search_roll=int(input("Enter the roll number of the student to be searched :"))
flag=0
while True:
try:
r=pickle.load(f2)
if r[0]==search_roll:
updated_marks=int(input("Enter the new marks"))
r[2]=updated_marks
flag=1
except EOFError:
break
if flag==0:
print("Student not found")
else:
print("Marks updated successfully")
f2.close()
OUTPUT:

File:

______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 15

AIM: Program to create CSV file and store empno,name,salary and search
any empno and display name,salary and if not found appropriate
message

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:
import csv
f1=open("empolyee.csv","a", newline="")
w=csv.writer(f1)
num=int(input("Enter the number of employee whose data is to be entered :"))
for i in range(num):
empno=int(input("Enter the employee number :"))
name=input("Enter the name of the employee :")
sal=int(input("Enter the salary of the employee :"))
data=[empno,name,sal]
w.writerow(data)
f1.close()
search=int(input("Enter the employee no. of the employee to be searched :"))
flag=0
f2=open("emp.csv","r")
r=csv.reader(f2)
for i in r:
if i[0]==search:
print("name of the employee is :",i[1])
print("salary of the employee is :",i[2])
flag=1
if flag==0:
print("employee not found")
f2.close()
OUTPUT:

File:

______________________________________________________________
18/08/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 16

AIM: Program to generate random number 1-6, simulating a dice.

SOFTWARE USED: IDLE (PYTHON 3.8 64-bit)

INPUT:

import random
result=random.randint(1,6)
print("the result of the dice is :",result)

OUTPUT:

______________________________________________________________
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 17

AIM: Write brief detail about SQL and its commands

INPUT:

SQL:
The Structured Query Language (SQL) is a language that enables you to
create and operate on relational databases, which are sets of related
information stored in tables.

CLASSIFICATION OF SQL STATEMENTS SQL


commands can be mainly divided into following categories:
1. Data Definition Language(DDL) Commands:
Commands that allow you to perform task, related to data definition e.g;
• Creating, altering and dropping.
• Granting and revoking privileges and roles
• Maintenance command

2. Data Manipulation Language(DML) Commands


Commands that allow you to perform data manipulation e.g., retrieval,
insertion, deletion and modification of data stored in a database.

3. Transaction Control Language(TCL) Commands


Commands that allow you to manage and control the transactions e.g.,
• Making changes to database, permanent
• Undoing changes to database, permanent
• Creating savepoints
• Setting properties for current transactions

______________________________________________________________
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 18

AIM: Write the SQL command/query based on Creation, Insertion, Deletion &
pattern Matching.

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. Write the command to create the table STUDENT

OUTPUT:

2. Write the command to insert the values in the table STUDENT.

OUTPUT:
3. Write the command to select distinct Streams in the table STUDENT

4. Write the command to display details of all students whose name starts
with D.

5. Write the command to display details of all students that have second
character ‘i’ in their name
06/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 19
AIM: Write the SQL command/query based on Alter, Update, Deletion and
Sorting with reference to the STUDENT table.

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. Write a command to update marks of student having admission number
8765 to 76

Output:

2. Write a command to view structure of the table STUDENT


3. Write a command to display details of all students whose marks falls
between 80 and 100

4. Write a command to display Name and Stream of all students who have
Nonmedical stream

5. Write a command to display Name, Stream and Marks of all students in


descending order of Marks

6. Write a command to delete the data of students who have Medical


Stream
Output

7. Write a command to add a new column Grade in the table STUDENT

Output:

8. Write command to delete the column added in Q7

Output:

______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 20

AIM:Write the SQL command/query based on Aggregate Functions with


reference to the STUDENT table.

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. Write a command to compute sum of marks of students in student table

2. Write a command to display maximum Marks in STUDENT table.

3. Write a command to display minimum Marks in STUDENT table

4. Write a command to display average of Marks in STUDENT table.

5. Write a command to display the total number of student in student table

______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 21

AIM: Write the SQL command/query based on Group by and having clause
with reference to the STUDENT table

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. Write command to count number of students in each Streams

2. Write command to find max marks obtained by student in each Stream.

3. Write command to display only those streams where number of


students are greater than 2
4. Write command to display that class who have total number of students
greater than 5

______________________________________________________________
26/10/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 22

AIM; Write the SQL command/query based on Single Row functions with
reference to the STUDENT table.

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. Write command to extract the first 2 characters from Name column

2. Write command to display the total number of characters in each value


of column Name
3. Write a command to display all the values in stream column in upper
case letters.

4. Write command to concatenate Name, Class and section of all students


who are in class 12

5. Write command to extract the last three characters from the Name
column

______________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 23

AIM: Write the SQL command/query based on Joins.

SOFTWARE USED: MySQL workbench 8.0 CE

INPUT:
1. To display names of participants along with workshop titles for only
those workshops that have more than 2 speakers

2. To display ParticipantID, Participant’s name, WorkshopId for workshops


meant for Senior Managers and Junior Managers

3. To display WorkshopId, title , ParticipantId for only those workshops that


have fees in the range of 5000.00 to 8000.00

_________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 24

AIM: Program to connect with database and store record of employee and
display records

SOFTWARE USED: 1- IDLE (PYTHON 3.8 64-bit)

2- MySQL workbench 8.0 CE

INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
cur=conn.cursor()
cur.execute("insert into employee values({},'{}','{}',{})".format(121,"Kartik
singh","IT",40000))
cur.execute("insert into employee values({},'{}','{}',{})".format(324,"Deepa
kumari","HR",34000))
cur.execute("insert into employee values({},'{}','{}',{})".format(754,"Mahesh
singh","MARKETING",23500))
cur.execute("insert into employee values({},'{}','{}',{})".format(432,"Anuj
kumar","HR",35000))
cur.execute("insert into employee values({},'{}','{}',{})".format(234,"Aarti","IT",
45000))
conn.commit()
print("Data inserted successfully")
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
print(i)
conn.close()
OUTPUT :
Python :

Sql:

______________________________________________________________
16/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 25

AIM:Program to connect with database and search employee number in table


employee and display record, if empno not found display appropriate
message

SOFTWARE USED: 1- IDLE (PYTHON 3.8 64-bit)

2- MySQL workbench 8.0 CE

INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904"
, database="practical")
cur=conn.cursor()
cur.execute("select * from employee")
c=cur.fetchall()
flag=0
number=int(input("enter the employee number to be searched"))
for i in c:
if i[0]==number:
print("the employee number is :",i[0])
print("the employee name is :",i[1])
print("the employee department is :",i[2])
print("the employee salary is :",i[3])
flag=1
if flag==0:
print("the employee is not found")

OUTPUT :

______________________________________________________________
17/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 26

AIM : Program to connect with database and update the employee record of
entered empno

SOFTWARE USED: 1- IDLE (PYTHON 3.8 64-bit)

2- MySQL workbench 8.0 CE

INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
emp_num=int(input("Enter employee number to update :"))
flag=0
cur=conn.cursor()
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
if i[0]==emp_num:
print("employee number",emp_num,"found")
new_name=input("enter the new name :")
new_dept=input("enter the new department :")
new_sal=int(input("enter the new salary :"))
cur.execute("update employee set ename='{}',dept='{}',salary={} where
empno={}".format(new_name,new_dept,new_sal,
emp_num))
conn.commit()
print("data updated successfully")
flag=1
if flag==0:
print("employee not found")
conn.close()
OUTPUT:
Python :

SQL:

______________________________________________________________
17/11/2023
𝑃𝑅𝐴𝐶𝑇𝐼𝐶𝐴𝐿 − 27

AIM: Program to connect with database and delete the record of entered
employee number

SOFTWARE USED: 1- IDLE (PYTHON 3.8 64-bit)

2- MySQL workbench 8.0 CE

INPUT:
import mysql.connector as mycon
conn=mycon.connect(host="localhost",user="root",password="Shubh@1904",
database="practical")
emp_num=int(input("Enter employee number to delete the data from :"))
cur=conn.cursor()
flag=0
cur.execute("select * from employee")
c=cur.fetchall()
for i in c:
if i[0]==emp_num:
cur.execute("delete from employee where empno={}".format(emp_num))
print("data deleted successfully")
flag=1
conn.commit()
if flag==0:
print("data not found to be deleted")
conn.close()
OUTPUT:
Python:

SQL:

______________________________________________________________

You might also like