0% found this document useful (0 votes)
1 views39 pages

Practical File Python Set3

The document is a practical file for Computer Science submitted by Asutosh Agarwal for the session 2026-27 at Senior Secondary School, Aonla, Bareilly. It includes a certificate of completion, acknowledgments, and an index of various Python programs covering topics like HCF, factorial, Fibonacci series, file handling, and MySQL commands. The document serves as a comprehensive guide to the practical applications of Python in programming and data management.
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)
1 views39 pages

Practical File Python Set3

The document is a practical file for Computer Science submitted by Asutosh Agarwal for the session 2026-27 at Senior Secondary School, Aonla, Bareilly. It includes a certificate of completion, acknowledgments, and an index of various Python programs covering topics like HCF, factorial, Fibonacci series, file handling, and MySQL commands. The document serves as a comprehensive guide to the practical applications of Python in programming and data management.
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

SENIOR SECONDARY SCHOOL, AONLA

(BAREILLY)
AFFILIATED TO C.B.S.E BOARD ESTD. 1994

SESSION: - 2026-27
PRACTICAL
PRACTICAL FILE
FILE
COMPUTER SCIENCE
TOPIC-PYTHON & MySQL FILE

SUBMITTED TO:
SUBMITTED BY:
Mr. VIJAY KR. SHARMA ASHUTOSH
AGARWAL
PGT (COMPUTER SCIENCE) 12 TH COMMERCE
BAL VIDYAPEETH PUBLIC SCHOOL
AONLA, BAREILLY

CERTIFICATE

This is to certify that Asutosh Agarwal, a student of class

XII (Commerce) has successfully completed the practical

file of Computer Science under the guidance of

Mr. Vijay Kumar Sharma (PGT C.S.), for the partial

fulfilment of requirements for the course completion

during the year 2026-2027.

………………….. ………………..
Teacher in-Charge Principal

……………………
External Examiner
ACKNOWLEDGEMENT

Apart from the efforts of me, the success of any project depends largely on
the encouragement and guidelines of many others. I take this opportunity to
express my gratitude to the people who have been instrumental in the successful
completion of this project.

I express deep sense of gratitude to almighty God for giving me strength for
the successful completion of the project.

I express my heartfelt gratitude to my parents for constant encouragement


while carrying out this project.

I gratefully acknowledge the contribution of the individuals who contributed


in bringing this project up to this level, who continues to look after me despite my
flaws,

I express my deep sense of gratitude to the luminary The Principal, Bal


Vidhyapeeth Public School Aonla, Bareilly who has been continuously motivating
and extending their helping hand to us.

My sincere thanks to Mr. Vijay Kumar Sharma, Master In-charge, A


guide, Mentor all the above a friend, who critically reviewed my project and
helped in solving each and every problem, occurred during implementation of the
project

The guidance and support received from all the members who contributed
and who are contributing to this project, was vital for the success of the project. I
am grateful for their constant support and help.
INDEX
SERIAL TITLE OF PROGRAM PAGE
NO. NO.
1 HCF of two Numbers 4
2 Factorial of a number 5

3 Fibonacci Series to nth Term 6

4 Sum of all elements in a list 7


5 Occurrence of any word in a string 8
6 Reading file line by line and printing 9

7 Read Lines of a file and store it in a List 10

8 Number of names in a Text File 11

9 Frequency of words in a Text File 12

10 Copying Text File Contents 13

11 Display File size and File contents in Upper 15

12 Store and search Details using Binary file 16

13 Binary file Updating 18

14 Store and Search details Using CSV file 20


15 Simulating Dice using Random module 22
16 Stack implementation 23

17 Phishing - common word occurring 26


18 Facebook using Dictionary 27
19 Armstrong or Palindrome number 29
20 Temperature Plotting using the pyplot 30
21 Employee Details– Interfacing with MySQL 31
22 MSQL Commands 36

;
Program: 01 HCF of two Numbers
Write an application program using python to find HCF of Two numbers using function
concept

Program:

def hcf(x, y):


if x > y:
smaller = y
else:
smaller = x
for i in range(1,smaller + 1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
# Main Block
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The H.C.F. of", num1,"and", num2,"is", hcf(num1, num2))

Output :

Enter first number: 16


Enter second number: 4
The H.C.F. of 16 and 4 is 4

Program: 02 Factorial of a number


Write an application program using python to find the factorial of a number using function
concept.

Program:

def factorial(n):
if n == 1:
return n
else:
f=1
for a in range(1,(n+1)):
f*=a
return f

# Main Block

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


# check is the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of",num,"is",factorial(num))

Output:
Enter a number: 6
The factorial of 6 is 720

Program: 03 Fibonacci Series to nth Term


Write an application program using python to print the fibonocci series till given nth term

Program:

def fibo(n):
if n <= 1:
return n
else:
f1=0
f2=1
f=f1+f2
FL=[f1,f2]
while n>0:
[Link](f)
f1=f2
f2=f
f=f1+f2
n=n-1
return FL

#Main Block
nterms = int(input("Enter a number to limit the fibonocci series:"))
if nterms <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
print(fibo(nterms-2))

Output:

Enter a number to limit the fibonocci series:15

Fibonacci sequence:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]

Program: 04 Sum of all elements in a list


Write an application program using python to find the sum of all elements of list

Program:

def sum_arr(arr,size):

if (size == 0):
return 0
else:
sum=0
for a in arr:
sum+=a
return sum
# Main Block
n=int(input("Enter the number of elements for list:"))
a=[ ]
for i in range(0,n):
element=int(input("Enter element"+str(i+1)+":"))
[Link](element)
print("The list is:")
print(a)
print("Sum of items in list:",sum_arr(a,n))

Output:
Enter the number of elements for list:5
Enter element1:10
Enter element2:20
Enter element3:30
Enter element4:40
Enter element5:50
The list is:
[10, 20, 30, 40, 50]
Sum of items in list: 150

Program: 05 Occurrence of any word in a string


Write an application program using python to find the Occurrence of any word in a string

Program:

def countWord(str1,word):
s = [Link]()
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:

Enter any sentence :my india, my kerala, my palakkad


Enter word to search in sentence :my
## my occurs 3 times ##

Program: 06 Reading file line by line and printing


Write an application program using python to Appending Lines to the file, reading that file
line by line and printing

Program:

L = ["God \n", "is \n", "Love\n"] # Creation of list with three lines

file1 = open('[Link]', 'w') # Opening a flie for writting


[Link](L) #Appending a lines to the file
[Link]() # Closing the file

file1 = open('[Link]', 'r') # Opening a flie for reading


Lines = [Link]() # reading Lines from the file

count = 1
for line in Lines:
print("Line{}: {}".format(count, [Link]())) # Displaying Each Line of file using
For Loop
count+=1

Output:

Line1: God
Line2: is
Line3: Love

Program: 07 Read Lines of a file and store it in a List


Write an application program using python to

Program:

L = ["Python \n", "is a \n", "Programming Language \n"]

file1 = open('[Link]', 'w') # Opening a flie for writting


[Link](L) #Appending a lines to the file
[Link]() # Closing the file

file1 = open('[Link]', 'r') # Opening a flie for reading


Lines = [Link]() # reading Lines from the file

count = 1
lst=[] # creating a list
for line in Lines:
print("Line{}: {}".format(count, [Link]())) # Displaying Each Line of file using
For Loop
lst. append(line) # Storing each line in to a List
count+=1
print ("Lines in a file is stored in alist : ")
print(lst) #displaying the list

Output:

Line1: Python
Line2: is a
Line3: Programming Language
Lines in a file is stored in alist :
['Python \n', 'is a \n', 'Programming Language \n']
>>>

Program: 08 Number of names in a Text File


Write an application program using python to count the number of names in a text file
(each name stored in separate lines)

Program:

file1 = open('[Link]', 'w')


num= int(input("Enter total number of names :"))# Opening a flie for writting
for i in range(num):
name=input("Enter name"+str(i+1)+":")
[Link](name+"\n") #Appending a lines to the file
[Link]() # Closing the file

file1 = open('[Link]', 'r') # Opening a flie for reading


Lines = [Link]() # reading Lines from the file
count=0
print ("Name File Contents\n************")
for a in Lines:
print(a)
count+=1 # counting
print ("Total Number of names in a file is : ",count )
[Link]()

Output:
Enter total number of names :4
Enter name1:John
Enter name2:Ram
Enter name3:Raheem
Enter name4:Suraj

File Contents
************
John
Ram
Raheem
Suraj

Total Number of names in a file is : 4


Program: 09 Frequency of words in a Text File
Write an application program using python, To count the number/ frequency of words in a
Text File

Program:

file1 = open('[Link]', 'w')


num= int(input("Enter total number of lines :"))# Opening a flie for writting
for i in range(num):
line=input("Enter line"+str(i+1)+":")
[Link](line+"\n") #Appending a lines to the file
[Link]() # Closing the file

file1 = open('[Link]', 'r') # Opening a flie for reading


words= [Link]().split() # reading Lines from the file
count=0
for word in words:
count+=1 # counting
print ("Total Number of words in a file is : ",count )
[Link]()

Output:

Enter total number of lines :3

Enter line1:hai
Enter line2:how are you
Enter line3:welcome back

Total Number of words in a file is : 6

Program: 10 Copying Text File Contents


Write an application program using python, to Copying contents of one text file and
appending into another text file

Program:

print("First file \n***********")


f = open('[Link]', 'w')
num= int(input("Enter total number of Lines :"))# Opening a flie for writting
for i in range(num):
Line=input("Enter Line"+str(i+1)+":")
[Link](Line+"\n") #Appending a lines to the file
[Link]() # Closing the file

print("Second file \n***********")


s = open('[Link]', 'w')
num= int(input("Enter total number of Lines :"))# Opening a flie for writting
for i in range(num):
Line=input("Enter Line"+str(i+1)+":")
[Link](Line+"\n") #Appending a lines to the file
[Link]()

f = open('[Link]','r')
print ("\nContents in the First file ")
for word in [Link]().split():
print(word, end=' ')
[Link]

s = open('[Link]', 'r')
print ("\nContents in the Second File ")
for word in [Link]().split():
print(word,end=' ')
[Link]()

# Copying the file contents


f = open('[Link]','r')
s = open('[Link]', 'a')
for word in [Link]().split():
[Link](word)
[Link]("\n")
[Link]
[Link]()

print ("\nContents in the Second File after copying from the First file: ")
s = open('[Link]', 'r')
for word in [Link]().split():
print(word,end=' ')
[Link]()

Output

First file
***********
Enter total number of Lines :2
Enter Line1:hello
Enter Line2:welcome to SRCS
Second file
***********
Enter total number of Lines :3
Enter Line1:St Raphaels cathedral school
Enter Line2:Senior Secondary school
Enter Line3:CBSE affliated,

Contents in the First file:


hello welcome to SRCS

Contents in the Second File:


St Raphaels cathedral school Senior Secondary school CBSE affliated,

Contents in the Second File after copying from the First file:
St Raphaels cathedral school Senior Secondary school CBSE affliated, hello welcome to
SRCS

Program: 11 Display File size and File contents in Upper case


Write an application program using python, to Display File size and File contents in Upper
case

Program:

print("File Entry \n***********")


f = open('[Link]', 'w')
num= int(input("Enter total number of Lines :"))# Opening a flie for writting
for i in range(num):
Line=input("Enter Line"+str(i+1)+":")
[Link](Line+"\n") #Appending a lines to the file
[Link]() # Closing the file

def file_size(fname): # function for finding the file size


import os
statinfo = [Link](fname)
return (statinfo.st_size)-3

def Upper(fname): # converting the file contents to upper case


file1=open(fname,'r')
for word in [Link]().split():
print([Link](),end=' ')

print("File size in bytes of a plain file: ",file_size("[Link]"))


print("File contents in upper case: ",end='')
Upper("[Link]")

Output:

File Entry
***********
Enter total number of Lines :1
Enter Line1:My best school, SRCS
File size in bytes of a plain file: 19
File contents in upper case: MY BEST SCHOOL, SRCS
Program: 12 Store and search Details using Binary file
Write an application program using python,to create binary file to store Rollno and Name,
Search any Rollno and display name if Rollno found otherwise “Rollno not found”

Program:

import pickle
student=[]
f=open('[Link]','wb')
ans='y'
while [Link]()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
[Link]([roll,name])
ans=input("Add More ?(Y)")
[Link](student,f)
[Link]()

f=open('[Link]','rb')
student=[]
while True:
try:
student = [Link](f)
except EOFError:
break

ans='y'
while [Link]()=='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) :")
[Link]()

Output:

Enter Roll Number :1


Enter Name :John
Add More ?(Y)y
Enter Roll Number :2
Enter Name :Ram
Add More ?(Y)y
Enter Roll Number :3
Enter Name :Raheem
Add More ?(Y)n
Enter Roll number to search :3
## Name is : Raheem ##
Search more ?(Y) :y
Enter Roll number to search :4
####Sorry! Roll number not found ####
Search more ?(Y) :n

Program :13 Binary file Updating


Write an application program using python, to create binary file to store Rollno, Name and
mark , let user to change the marks entered.

Program:

import pickle
student=[]
f=open('[Link]','wb')
ans='y'
while [Link]()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
marks = int(input("Enter Marks :"))
[Link]([roll,name,marks])
ans=input("Add More ?(Y)")
[Link](student,f)
[Link]()

f=open('[Link]','rb+')
student=[]
while True:
try:
student = [Link](f)
except EOFError:
break

ans='y'
while [Link]()=='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) :")
[Link]()
Output:

Enter Roll Number :1


Enter Name :John
Enter Marks :98
Add More ?(Y)y
Enter Roll Number :2
Enter Name :Ram
Enter Marks :97
Add More ?(Y)n
Enter Roll number to update :2
## Name is : Ram ##
## Current Marks is : 97 ##
Enter new marks :99
## Record Updated ##
Update more ?(Y) :n

Program :14 Store and Search details Using CSV file

Aim:
Write an application program using python, to create CSV file and store
empno,name,salary and search any empno and display name,salary and
if not foundappropriate message.

Program:
import csv
with open('[Link]',mode='a') as csvfile:
mywriter = [Link](csvfile,delimiter=',')
ans='y'
while [Link]()=='y':
eno=int(input("Enter Employee Number "))
name=input("Enter Employee Name ")
salary=int(input("Enter Employee Salary :"))
[Link]([eno,name,salary])
print("## Data Saved... ##")
ans=input("Add More ?")

with open('[Link]',mode='r') as csvfile:


myreader = [Link](csvfile,delimiter=',')
ans='y'
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("NAME :",row[1])
print("SALARY :",row[2])
found=True
break
if not found:
print(" EMPNO NOT FOUND")
ans = input("Search More ? (Y)")

Output:
Enter Employee Number 1
Enter Employee Name Aswathy
Enter Employee Salary :25000
## Data Saved... ##
Add More ?y
Enter Employee Number 2
Enter Employee Name Riyas
Enter Employee Salary :30000
## Data Saved... ##
Add More ?n
Enter Employee Number to search :2
NAME: Riyas
SALARY : 30000
Search More ? (Y) n

Program: 15 Simulating Dice using Random module


Write an application program using python, to generate random number 1-6,
simulating a dice

Program:
import random
import time
print("Press CTRL+C to stop the dice ")
play='y'
while play=='y':
try:
while True:
for i in range(10):
print(i)
n = [Link](1,6)
print(n,end='')
[Link](.10)
except KeyboardInterrupt:
print("Your Number is :",n)
ans=input("Play More? (Y) :")
if [Link]()!='y':
play='n'
break

Ourput: (for getting output press ctrl+c)


6Your Number is : 6
Play More? (Y) :y
0
1
2
3
4
5
6
7
8
9
3Your Number is : 3
Play More? (Y) :y

Program: 16 Stack implementation


Write an application program to implement Stack in Python using List

Program:

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

def Push(S,item):
[Link](item)
top=len(S)-1

def Pop(S):
if isEmpty(S):
return "Underflow"
else:
val = [Link]()
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

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 :0 Bye

Program: 17 Phishing - common word occurring

Aim:
Write an application program totake 10 sample phishing email, and find the most common
word occurring using List

Program:

phishingemail=[
"jackpotwin@[Link]",
"claimtheprize@[Link]",
"youarethewinner@[Link]",
"luckywinner@[Link]",
"spinthewheel@[Link]",
"dealwinner@[Link]",
"luckywinner@[Link]",
"luckyjackpot@[Link]",
"claimtheprize@[Link]",
"youarelucky@[Link]"
]
myd={}
for e in phishingemail:
x=[Link]('@')
for w in x:
if w not in myd:
myd[w]=1
else:
myd[w]+=1
key_max = max(myd,key=[Link])
print("Most Common Occurring word is :",key_max)
Output:

Most Common Occurring word is : [Link]

Program: 18 Facebook using Dictionary


Write an application program to create profile of users using dictionary, also let the users
to search, delete and update their profile like face book application

Program:

FB={}
n=int(input(" enter no of details to be need "))
for i in range(n):
print (" FB NO ", i+1)
id=int(input(" enter id "))
na=input(" enter the name ")
pl=input(" enter ur place ")
nk=input(" enter profile name ")
r=[na,pl,nk]
FB[id]=r

k=[Link]()
while True:
c=input(" \n please enter: 'S' for search : 'D' for delete : 'U' for update : ")
if(c in'Ss'):
se=input(" enter the searching name ")
for i in k:
x=FB[i]
if(x[0]==se):
print (" searching record is : NAME : ",x[0]," , PLACE : ",
x[1] ," ,PROFILE NAME : ", x[2])
elif(c in 'dD'):
x=int(input(" enter id "))
if (x in k):
print(" deleted record is ", FB[x])
del FB[x]
else:
print ("invalid id")
elif(c in 'Uu'):
x=int(input (" enter the id "))
if(x in k):
v=FB[x]
na=v[0]
upl=input(" enter place ")
unk=input(" enter profile name")
FB[x]=[na,upl,unk]
print(" updated record is " ,FB[x])
else:
print(" invalid id")
ch=input(" Do you want to continue y/n")
if(ch!='y'):
break
Output:

enter no of details to be need 1


FB NO 1
enter id 1
enter the name sree
enter ur place pkd
enter profile name sri

please enter: 'S' for search : 'D' for delete : 'U' for update : s
enter the searching name sree
searching record is : NAME : sree , PLACE : pkd ,PROFILE NAME : sri
Do you want to continue y/ny

please enter: 'S' for search : 'D' for delete : 'U' for update : u
enter the id 1
enter place thr
enter profile namesreeja
updated record is ['sree', 'thr', 'sreeja']
Do you want to continue y/ny

please enter: 'S' for search : 'D' for delete : 'U' for update : d
enter id 2
invalid id
Do you want to continue y/n

Program: 19 Armstrong or Palindrome number

Aim:
Write an application program to, Check whether a number is (i) palindrome (ii)
Armstrong by function with return multiple values

Program:

def calc(n):
s=0
r=0
while n>0:
d=n%10
r=r*10 + d
s=s+d*d*d
n//=10
return s,r
#main

n=int(input(" enter a number "))


x,y=calc(n)
if(n==1):
print( " ARMSTRONG & PALINDROME ")
elif(n==x):
print( " ARMSTRONG ")
elif(y==n):
print(" PALINDROME ")
else:
print(" SORRY , Not a Palindrome or Not an Armstrong number")

Output:

enter a number 153


ARMSTRONG

enter a number 1
ARMSTRONG & PALINDROME

enter a number 12721

PALINDROME

Program: 20 Temperature Plotting using the pyplot


Write an application program Plot the temperature of various districts using the pyplot or
matplot libraries

Program:

import [Link] as plt


x = ['pkd','thr','kch']
y = [25,40,20]
[Link](x, y)
[Link]('Districts')
[Link]('Temparature')
[Link]('Temparature Plotting')
[Link]()
Output:

Program: 21.a Data Insertion – Python with MySQL


Write an application program to interface python with SQL database for employees data
insertion .

Program:

import [Link] as m
def insertion():
try:
con=[Link](host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('Successfully connected')
mycur=[Link]()
empid=int(input("Enter Employee ID :"))
empname= input("Enter employee name :")
query="insert into employee values ({},'{}')".format(empid,empname)
[Link](query)
[Link]()
print ("Record inserted successfully")
[Link]();
[Link]()
except Exception as e:
print(e)

#Main block

insertion()

Output
Successfully connected
Enter Employee ID : 101
Enter employee name :Arjun
Record inserted successfully

Program: 21.b Data Deletion – Python with MySQL


Write an application program to interface python with SQL database for employees data
deletion.

Program:
import [Link] as m
def deletion():
try:
con=[Link](host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('successfully connected')
mycur=[Link]()
empid=int(input("Enter Employee ID to be deleted :"))
query="delete from employee where empid={}".format(empid)
[Link](query)
[Link]()
print ("Record deleted successfully")
[Link]();
[Link]()
except Exception as e:
print(e)

#Main Block

deletion()

Output
Successfully connected
Enter Employee ID to be deleted : 101

Record deleted successfully

Program: 22 MY SQL

1. CREATE DATABASE
Create a Database of name EMPLOYEE.

QUERY

 CREATE DATABASE EMPLOYEE;

2. OPEN COMMAND
Open the Database using the USE command.
QUERY
 USE DATA

3. CREATE TABLE
Create table EMP with specified number of rows and columns and apply necessary constraints.
QUERY
 CREATE TABLE EMP
(ENO INTEGER PRIMARYKEY, ENAME VARCHAR (20) UNIQUE,
JOB VARCHAR (20) DEFAULT “CLERK”, GENDER CHAR (1) NOT
NULL, HIRE DATE, SAL FLOAT (6,2) CHECK SAL>2000,COMM INTEGER);

4. INSERT COMMAND
Insert tuples to the table EMP.

QUERY
 INSERT INTO EMP VALUES(1,’KING’,’MANAGER’,’M’,’1981-11-
17’,5000,NULL);
 INSERT INTO EMP VALUES(2,’BLAKE’,’MANAGER’,’M’,’1981-05-
01’,2850,NULL);
 INSERT INTO EMP VALUES(3,’JASMIN’,’SALESMAN’,’F’,’1982-12-
09’,2450,300);
 INSERT INTO EMP VALUES(4,’JONES’,’SALESMAN’,’M’,’1983-01-
12’,2975,500);
 INSERT INTO EMP VALUES(5,’CLARK’,’ANALYST’,’M’,’1983-01-
23’,1250,NULL);
 INSERT INTO EMP VALUES(6,’GEETHA’,’CLERK’,’F’,’1981-02-
22’,1600,NULL);

5. SELECT COMMAND
Display all employee details.
QUERY
 SELECT * FROM EMP;
OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


1 KING MANAGER M 1981-11-17 5000.00 NULL
2 BLAKE MANAGER M 1981-05-01 2850.00 NULL
3 JASMIN SALESMAN F 1982-12-09 2450.00 300
4 JONES SALESMAN M 1983-01-12 2975.00 500
5 CLARK ANALYST M 1983-01-23 1250.00 NULL
6 GEETHA CLERK F 1981-02-22 1600.00 NULL

AIM
Display ENO, ENAME and JOB of all Employees.
QUERY
 SELECT ENO,ENAME,JOB FROM EMP;

OUTPUT

ENO ENAME JOB


1 KING MANAGER
2 BLAKE MANAGER
3 JASMIN SALESMAN
4 JONES SALESMAN
5 CLARK ANALYST
6 GEETHA CLERK
6. USING DISTINCT KEYWORD
AIM
Display job of employee by eliminating redundant data.
QUERY
 SELECT DISTINCT JOB FROM EMP;
OUTPUT

DISTINCT JOB
MANAGER
SALESMAN
ANALYST
CLERK

7. USING WHERE CLAUSE


AIM
Display all details of employee who is having job as salesman.
QUERY
 SELESCT * FROM EMP WHERE JOB=’SALESMAN’;

OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


3 JASMIN SALESMAN F 1982-12- 2450.00 300
09
4 JONES SALESMAN M 1983-01- 2975.00 500
12
8. RELATIONAL OPERATOR
AIM
Display the details of employee whose name is not ‘KING’.

QUERY
 SELECT * FROM EMP WHERE ENAME<>’KING’;
OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


2 BLAKE MANAGER M 1981-05-01 2850.00 NULL
3 JASMIN SALESMAN F 1982-12-09 2450.00 300
4 JONES SALESMAN M 1983-01-12 2975.00 500
5 CLARK ANALYST M 1983-01-23 1250.00 NULL
6 GEETHA CLERK F 1981-02-22 1600.00 NULL
AIM
Display the details of employee ENO,ENAME,SAL of people whose salary is above 2500.
QUERY
 SELECT ENO,ENAME,SAL FROM EMP WHERE SAL>2500;
OUTPUT

ENO ENAME SAL


1 KING 5000.00
2 BLAKE 2850.00
4 JONES 2975.00
9. LOGICAL OPERATORS
AIM
Display the details of employee whose job is manager or gender is male.

QUERY
 SELECT * FROM EMP WHERE JOB=’MANAGER’ OR GENDER=’M’;

OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


1 KING MANAGER M 1981-11-17 5000.00 NULL
2 BLAKE MANAGER M 1981-05-01 2850.00 NULL
4 JONES SALESMAN M 1983-01-12 2975.00 500
5 CLARK ANALYST M 1983-01-23 1250.00 NULL
AIM
Display the ENO, ENAME and COMM of employees with commission.

QUERY
 SELECT ENO,ENAME,COMM FROM EMP WHERE COMM IS NOT NULL;

OUTPUT

ENO ENAME SAL JOB


3 JASMIN 2450.00 SALESMAN
4 JONES 2975.00 SALESMAN

AIM
Display the details of employees whose job is not salesman.
QUERY
 SELECT * FROM EMP WHERE JOB NOT=’SALESMAN’;
OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


1 KING MANAGER M 1981-11-17 5000.00 NULL
2 BLAKE MANAGER M 1981-05-01 2850.00 NULL
5 CLARK ANALYST M 1983-01-23 1250.00 NULL
6 GEETHA CLERK F 1981-02-22 1600.00 NULL

10. USING BETWEEN- AND CLAUSE


AIM
Display the details of employees whose salary is between 2000 and 5000.
QUERY
 SELECT * FROM EMP WHERE SAL BETWEEN 2000 AND 5000;
OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


1 KING MANAGER M 1981-11-17 5000.00 NULL
2 BLAKE MANAGER M 1981-05-01 2850.00 NULL
3 JASMIN SALESMAN F 1982-12-09 2450.00 300
4 JONES SALESMAN M 1983-01-12 2975.00 500

AIM
Display the details of employees whose salary is not between 2000 and 5000.
QUERY
 SELECT * FROM EMP WHERE SAL NOT BETWEEN 2000 AND 5000;
OUTPUT

ENO ENAME JOB GENDER HIRE SAL COMM


5 CLARK ANALYST M 1983-01-23 1250.00 NULL
6 GEETHA CLERK F 1981-02-22 1600.00 NULL

You might also like