0% found this document useful (0 votes)
7 views41 pages

XII Practical Programs

The document outlines various programming tasks including reading files line by line, counting characters, creating and updating binary files, removing lines from files, generating random numbers, checking for palindromes, summing diagonals in matrices, and implementing a menu application for ASCII values. Each task includes an aim, algorithm, code, and results demonstrating successful execution. The tasks cover fundamental programming concepts and file handling techniques.

Uploaded by

h22633919
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)
7 views41 pages

XII Practical Programs

The document outlines various programming tasks including reading files line by line, counting characters, creating and updating binary files, removing lines from files, generating random numbers, checking for palindromes, summing diagonals in matrices, and implementing a menu application for ASCII values. Each task includes an aim, algorithm, code, and results demonstrating successful execution. The tasks cover fundamental programming concepts and file handling techniques.

Uploaded by

h22633919
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

1.

READING A FILE LINE BY LINE


AIM:
The aim of the program is to read a file contents line by line and print the contents with
each word separated by #.
ALGORITHM:
Step 1: Start the program
Step 2: Open text file in read mode and store it in file object.
Step 3: using for loop split the word using split function.
Step 4: using for loop concatenate words with ‘# ‘.
Step 5: print the word
Step 6: Close the file.
Step 7: end the program
CODE:
f = open('[Link]','r')
for l in f:
w = [Link]()
for o in w:
print(o+"#",end="")
print()
[Link]()
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Rose#is#beautiful#
I # Love # India#
India # is # my # country#
2. READ THE CONTENT OF FILE
AIM:
The aim of the program is to read the content of file and display total number of vowels
consonants lower case and uppercase characters.
ALGORITHM:
Step 1: Start the program
Step 2: Open text file in read mode and store it in file object my files.
Step 3: initialize vowels, consonants, uppercase, lowercase and others as 0.
Step 4: using for read my file if its is alphabet check upper or lower then increment
appropriate variable by 1.
Step 5: check it for vowels then increment vowels by 1.
Step 6: Close the file .
Step 7: end the program
CODE:
f = open('[Link]','r')
v=0
c=0
s=0
u=0
o=0
d = [Link]()
for i in d:
if [Link]() in 'aeiou':
v += 1
elif [Link]().isalpha() and [Link]() not in 'aeiou':
c +=1
elif [Link]():
s +=1
elif [Link]():
u+=1
elif [Link]()!=True and i !="\n":
o+=1
print("Total Vowels in the file is:",v)
print("Total Consonants in the file is:",c)
print("Total Small Letters in the file is:",s)
print("Total Capital Letters in the file is:",u)
print("Total No of characters other than letters in the file is:",o)
RESULT:
Thus the program was created and executed successfully.
OUTPUT:

Total vowels in file: 11

Total consonants in file: 19

Total capital letters in file: 4

Total small letters in file: 26

Total other than letters : 7


3. CREATION OF BINARY FILE
AIM:
The aim of the program is to create a binary file to store roll number and name , search for
roll number and display the record if found.
ALGORITHM.
Step 1: Start the program
Step 2: Import necessary header files.
Step 3: Open binary file, get the input name, roll number from the user.
Step 4: Using the while loop , get the roll number found ,otherwise print the message that
roll number not found.
Step 5: Print the record ,if the roll number found , otherwise print the message that roll
number not found.
Step 6: Close the file .
Step 7: End the program

CODE:
import pickle
student=[]
f=open('[Link]','wb')
ans='y'
while [Link]()=='y':
roll=int(input('Enter the roll number:'))
name=input('Enter the 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 no 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]()
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Enter the roll number:4
Enter the name:vidhya
Add more (Y): y
Enter the roll number:7
Enter the name:rose
Add more (Y): n
Enter roll no to search:7
##Name is rose ##
Search more?(y)n

4. UPDATING OF MARKS IN BINARY FILE


AIM:
The aim of the program is to create a binary file to store roll number name and marks
,update the marks for entered roll number.
ALGORITHM:
Step 1: Start the program
Step 2: Import necessary header files.
Step 3: Open binary file, get the input name, roll number from the user.
Step 4: Using the while loop , get the roll number to be searched from user.
Step 5: Update the marks for entered roll number .
Step 6: Close the file .
Step 7: End the program
CODE:
import pickle
student=[]
f=open('[Link]','wb')
ans='y'
while [Link]()=='y':
roll=int(input('Enter the roll number:'))
name=input('Enter the 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 no to update:'))
for s in student:
if s[0]==r:
print('##Name is',s[1],'##')
print('##Current mark is:',s[2],'##')
m=int(input('Enter new mark:'))
s[2]=m
print('Record updated')
found=True
break
if not found:
print('##Sorry!! Roll no not found')
ans=input('update more?(y)')
[Link]()

RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Enter the roll number:4
Enter the name:vini
Enter marks:65
Add more (Y): y
Enter the roll number:8
Enter the name:dharshini
Enter marks:89
Add more (Y): n
Enter roll no to update:8
##Name is dharshini ##
##Current mark is: 89 ##
Enter new mark:98
Record updated
update more?(y)n
5. REMOVING LINES FROM LINE
AIM:
The aim of the program is to remove all the lines that contain the character ‘a ‘ in the file and
write it to another file.
ALGORITHM:
Step 1. Start the program.
Step 2. Open infile in read mode.
Step 3. Read all lines from infile into a list called lines.
Step 4. Initialize two empty lists:
o lines_without_a (to store lines without 'a')
o lines_with_a (to store lines with 'a')
Step 5. Iterate through each line in lines:
o If 'a' is present, add the line to lines_with_a.
o If 'a' is not present, add the line to lines_without_a.
Step [Link] the infile.
Step 7. Open infile in write mode and overwrite it with lines_without_a.
Step 8. Open outfile in write mode and write lines_with_a into it.
Step 9. Print a confirmation message.
Step [Link] the program.
CODE:
infile=open('D:/practicals/pgm5/[Link]', 'r')
lines = [Link]()
lines_without_a=[]
lines_with_a=[]
for line in lines:
if 'a' in line:
lines_with_a.append(line)
else:
lines_without_a.append(line)
[Link]()
infile=open('D:/practicals/pgm5/[Link]', 'w')
[Link](lines_without_a)
outfile=open('D:/practicals/pgm5/[Link]', 'w')
[Link](lines_with_a)
[Link]()
[Link]()
print("Lines containing 'a' removed from ",infile," and saved in ",outfile)
RESULT:
Thus the program was created and executed successfully.

OUTPUT:
Lines containing 'a' removed from 'D:/practicals/pgm5/[Link]' and saved in
'D:/practicals/pgm5/[Link]'
6. RANDOM NUMBER GENERATOR
AIM:
The aim of the program is to generate random numbers between 1 to 6 using
random number generator.
ALGORITHM:
Step 1: Start the program
Step 2: Import random module into the program.
Step 3: create empty list a=[].
Step 4: Use a for loop, random .randint() is used to generate random numbers which are
then appending to list.
Step 5: Then print the randomized list.
Step 6: End the program

CODE:
import random
a = []
for j in range(1):
[Link]([Link](1,6))
print("Randomised list is:",a)
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Randomised list is: [3]
7. STRING PALINDROME
AIM:
The aim of the program is to test if a given string is palindrome or not.
ALGORITHM:
Step 1: Start the program
Step 2: Get the input from the user.
Step 3: Find the length of the string using l=len(str) and p=l-1.
Step 4: Initialize index value by 1 and decrement p value by 1.
Step 5: Using while check index value is less than p then increment index value by 1 and
decrement p value by 1.
Step 6: Otherwise print given string is palindrome.
Step 7: End the program
CODE:
st=input("Enter the string:")
l=len(st)
p=l-1
index=0
while (index<p):
if (st[index]==st[p]):
index=index+1
p=p-1
else:
print("String is not a palindrome")
break
else:
print("String is a palindrome")
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Enter the string:racecar
String is a palindrome

Enter the string:HELLO


String is not a palindrome
8. SUM OF DIAGONALS
AIM:
The aim of this program is to show sum of diagonals in two dimensional list.
ALGORITHM:
Step 1: Start the program
Step 2: Get two number of rows and number of columns as input from the user.
Step 3: Create an empty list as mylist
Step 4: Initialize sum d1 ,sum d2 equal to 0.
Step 5: Using for loop print the rows and columns as two dimensional list.
Step 6: Then print the values of two diagonals.
Step 7: End the program
CODE:
r=int(input("Enter number of Rows:"))
c=int(input("Enter number of Columns:"))
mylist=[]
#To create a Matrix
for i in range(0,r):
[Link]([])
for i in range(0,r):
for j in range(0,c):
mylist[i].append(j)
#To add values in Matrix
for i in range(0,r):
for j in range(0,c):
print("Enter the value:")
mylist[i][j]=int(input())
#To show Matrix
for i in range(0,r):
for j in range(0,c):
print(mylist[i][j],end=' ')
print('\n')
sumd1=0
sumd2=0
revlist=[]
for i in mylist:
[Link](i[::-1])
print(mylist,revlist,sep='\n')
print("Sum of diagonals in two dimensions of list are:")
for i in range(0,r):
sumd1=sumd1+mylist[i][i]
sumd2=sumd2+revlist[i][i]
print("Sum of diagonals 1 is:",sumd1)
print("Sum of diagonals 2 is:",sumd2)
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Enter number of Rows:2
Enter number of Columns:2
Enter the value:
4
Enter the value:
5
Enter the value:
65
Enter the value:
7
45

65 7

[[4, 5], [65, 7]]


[[5, 4], [7, 65]]
Sum of diagonals in two dimensions of list are:
Sum of diagonals 1 is: 11
Sum of diagonals 2 is: 70
9. MENU APPLICATION
AIM:
The aim of the program is to display ASCII code of a character and vice
versa.
ALGORITHM:
Step 1: Start the program
Step 2: Initialize var is equal to True.
Step 3: Get the input from the user.
Step 4: If choice is equal to 1,then get the value for that character.
Step 5: Using ord() function print ASCII value for character.
Step 6: If choice is equal to 2 then get the integer value from the user.
Step 7: Using chr() function print ASCII code for that integer.
Step 8: Otherwise print as wrong choice.
Step 9: End the program .
CODE:
var=True
while var:
choice=int(input("Press-1 to find the original value of a character\npress-2
to find a character of a value\n"))
if choice==1:
ch=input("Enter a character:")
print(ord(ch))
elif choice==2:
val=int(input("Enter a integer:"))
print(chr(val))
else:
print("You entered the wrong choice")
print("Do you want to continue? y/n")
option=input()
if option=='Y' or option=='y':
var=True
else:
var=False
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
Press-1 to find the original value of a character
press-2 to find a character of a value
1
Enter a character:S
83
Do you want to continue? y/n
Y
Press-1 to find the original value of a character
press-2 to find a character of a value
2
Enter a integer:67
C
Do you want to continue? y/n
N

10. STRING FUNCTIONS


AIM:
The aim of the program is to write a program to manipulate a string using
string functions
ALGORITHM:
Step 1: Start the program
Step 2 : Get the value of x,y,z,a,b,c,d,l,m from the user.
Step 3: Display "replacing operator".
Step 4: Display "concatenation operator".
Step 5: Display "membership operator".
Step 6: Display "not in membership operator".
Step 7: Display "comparison operator".
Step 8: End the program
CODE:

print("REPLICATING OPERATOR")

x=input("Enter a value:")

print(x*2)

print("CONCATENATION OPERATOR")

y=input("Enter a value:")

z=input("Enter the value:")

print(y+z)

print("MEMBERSHIP OPERATOR")

a=input("Enter the value:")

b=input("Enter the value to be searched:")

if b in a:

print("TRUE")

else:

print("FALSE")

print("NOT IN MEMBERSHIP OPERATOR")

d=input("Enter the value to be searched:")


c=input("Enter the value :")

if d not in c:

print("TRUE")

else:

print("FALSE")

print("COMPARISION OPERATOR")

l=input("Enter the value:")

h=input("Enter the value to be searched:")

if l==h:

print("TRUE")

else:

print("FALSE")

RESULT:
Thus the program was created and executed successfully.
OUTPUT:
REPLICATING OPERATOR
Enter a value:45
4545
CONCATENATION OPERATOR
Enter a value:6
Enter the value:89
689
MEMBERSHIP OPERATOR
Enter the value:3
Enter the value to be searched:3
TRUE
NOT IN MEMBERSHIP OPERATOR
Enter the value to be searched:7
Enter the value :789
FALSE
COMPARISION OPERATOR
Enter the value:87
Enter the value to be searched:87
TRUE
11. LIST MANIPULATION
AIM:
The aim of the program is to write a program to manipulate list using list
operator.
ALGORITHM:
Step 1: Start the program
Step 2: Joining list will join two lists.
Step 3: Replicating list will repeat the list and print it.
Step 4: Index method will return the index of the given number.
Step 5: Pop method will delete the number which has given index value.
Step 6: Remove method will delete the number which is in the statement.
Step 7: Clear method will clear the list as whole.
Step 8: Reverse method print the reverse of entire list.
Step 9: End the program .
CODE:
print("JOINING LIST")
l1=[1,2,3]
l2=[4,5,6]
l=l1+l2
print(l)
print("REPLICATING LIST")
l3=l2*2
print(l3)
print("INDEX METHOD")
print([Link](5))
print("POP METHOD")
print([Link](2))
print("CLEAR METHOD")
[Link]()
print(l)
print("REVERSE METHOD")
l=[1,2,3,4,5,6]
[Link]()
print(l)
print("REMOVE METHOD")
[Link](5)
print(l2)
RESULT:
Thus the program was created and executed successfully.
12. STUDENT DETAILS USING DICTIONARY
AIM:
The aim of the program is to enter student details using dictionary.
ALGORITHM:
Step 1: Start the program
Step 2: Initialize the Dictionary.
Step 3: Inside the for loop give four marks and roll number.
Step 4: Give print statement that print roll number and marks from the dictionary.
Step 5: End the program
CODE:
rno=[]
mks=[]
for i in range(4):
r,m=eval(input("Enter the roll no,marks:"))
[Link](r)
[Link](m)
d={rno[0]:mks[0],rno[1]:mks[1],rno[2]:mks[2],rno[3]:mks[3]}
print(d)
if d[2]>75:
print("Roll no 2 scored",d[2],"[>75]")
else:
print("Roll no 2 scored",d[2],"[<75]")
RESULT:
Thus the program was created and executed successfully.
OUTPUT:

JOINING LIST
[1, 2, 3, 4, 5, 6]
REPLICATING LIST
[4, 5, 6, 4, 5, 6]
INDEX METHOD
4
POP METHOD
3
CLEAR METHOD
[]
REVERSE METHOD
[6, 5, 4, 3, 2, 1]
REMOVE METHOD
[4, 6]
13. SIMPLE CALCULATOR
AIM:
The aim of the program is to create a graphical application that accepts user inputs
performs some operation on them and then write the output on screen.
ALGORITHM:
Step 1: Start the program
Step 2: import tkinter module in program.
Step 3: Define the function btnclick(), btnclear() , result().
Step 4: Create buttons 1 to 9 and call command btnclick().
Step 5: Create button and multiply , divide, subtract, and call command btnclick().
Step 6: Create button equal and call command esult.
Step 7: Create clear button and call command btnclear().
Step 8: End the program.
CODE:
from tkinter import *
def btn_click(number):
global operator
operator=operator+str(number)
[Link](operator)
def btn_clear():
global operator
operator=" "
res=[Link](operator)
def result():
global operator
res=str(eval(operator))
[Link](res)
root=Tk()
[Link]("Calculator")
operator=" "
strvar=StringVar()

ent=Entry(root,width=50,bd=5,font=('arial',10,'bold'),bg='grey',textvariable=strvar,
justify='right').grid(columnspan=4)
btn7=Button(root,text='7',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(7)).grid(row=1,column=0)
btn8=Button(root,text='8',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(8)).grid(row=1,column=1)
btn9=Button(root,text='9',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(9)).grid(row=1,column=2)
btnplus=Button(root,text='+',padx=10,pady=10,font=('arial',10,'bold'),bg='red',
command=lambda:btn_click('+')).grid(row=1,column=3)
btn4=Button(root,text='4',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(4)).grid(row=2,column=0)
btn5=Button(root,text='5',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(5)).grid(row=2,column=1)
btn6=Button(root,text='6',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(6)).grid(row=2,column=2)
btnminus=Button(root,text='-
',padx=10,pady=10,font=('arial',10,'bold'),bg='red',command=lambda:btn_click('-
')).grid(row=2,column=3)
btn1=Button(root,text='1',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(1)).grid(row=3,column=0)
btn2=Button(root,text='2',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(2)).grid(row=3,column=1)
btn3=Button(root,text='3',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(3)).grid(row=3,column=2)
btnmuliti=Button(root,text='*',padx=10,pady=10,font=('arial',10,'bold'),bg='red',
command=lambda:btn_click('*')).grid(row=3,column=3)
btn0=Button(root,text='0',padx=10,pady=10,font=('arial',10,'bold'),bg='royal
blue',command=lambda:btn_click(0)).grid(row=4,column=0)
btnclear=Button(root,text='clear',padx=10,pady=10,font=('arial',10,'bold'),bg='yellow',
command=lambda:btn_clear()).grid(row=4,column=1)
btnequal=Button(root,text='=',padx=10,pady=10,font=('arial',10,'bold'),bg='green',
command=result).grid(row=4,column=2)
btndivide=Button(root,text='/',padx=10,pady=10,font=('arial',10,'bold'),bg='red',
command=lambda:btn_click('/')).grid(row=4,column=3)
Label(root,text='BY
XII',font=('arial',10,'italic'),bg='grey',fg='green').grid(row=5,column=4)
[Link]()
RESULT:
Thus the program was created and executed successfully.
OUTPUT

14. STACK IMPLEMENTATION


AIM:
The aim of the program is to implement stack operation using list data
structure.
ALGORITHM:
Step 1: Start the program
Step 2: Define the function pus(),pop(),peek().
Step 3: Initialize stack is empty.
Step 4: Create a list and append to the another list, use list name, append to push the item
into the stack.
Step 5: Pop() is used to remove the last value from the stack and returns it.
Step 6: Get the input from the user if the value is equal to 1 then call push.
Step 7: If the value =2 the check whether the stack is empty otherwise delete the item.
Step 8: If the value=3 then check whether the stack is empty otherwise display topmost item
in the stack.
Step 9: If the value=4 , then display the content of the stack elements.
Step 10: End the program.
CODE:
def push(l):
b_id=int(input("enter the book id:"))
b_name=input("enter the book name:")
r=[b_id,b_name]
[Link](r)
return l
def pop(l):
if l==[]:
print("stack underflow")
print("the value removed is",[Link]())
return(l)
def peek(l):
if l==[]:
print("the stack is empty")
print("the top most value is",l[-1])
def dp (l):
if l==[]:
print("the stack is empty")
for i in l[::-1]:
print(i)
l=[]
while True:
print("______\[Link]\[Link]\[Link]\[Link]\[Link]\n______")
n=int(input("enter a choice:"))
if n==1:
l=push(l)
elif n==2:
l=pop(l)
elif n==3:
peek(l)
elif n==4:
dp(l)
elif n==5:
print("program over! !")
break
else:
print("invalid input")
RESULT:
Thus the program was created and executed successfully.
OUTPUT

OUTPUT
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:1
enter the book id:12
enter the book name:JAVA
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:1
enter the book id:5
enter the book name:PYTHON
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:1
enter the book id:7
enter the book name:C#
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:2
the value removed is [7, 'C#']
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:3
the top most value is [5, 'PYTHON']
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:4
[5, 'PYTHON']
[12, 'JAVA']
______
[Link]
[Link]
[Link]
[Link]
[Link]
______
enter a choice:5
program over! !
15. WORKING WITH CSV FILES
AIM:
The aim of the program is to create a CSV file by entering user-ID and password , read and
search the password for given userid.
ALGORITHM:
Step 1: Start the program
Step 2: Import CSV module
Step 3: Open CSV file with a file handle,
Step 4: Create writer object which writes data into CSV file
Step 5: Using writerow() write one row of data onto the writer object
Step 7: Check the condition if row[0]==user_id then print the password for the given
user_id.
Step 8: Get the input from the user if the value=[Link] CSv file ,if value=2 add data into
CSV file, if value=3 search password for the given user_id.
Step 9: End the program

CODE:
import csv
def create_csv(fn):
f = open(fn,'w',newline='')
writer = [Link](f)
[Link](['User_ID','Password'])
print("The csv file ",fn,"was created successfully")
[Link]()
def add_entry(fn,uid,passw):
f = open(fn,'a',newline='')
writer = [Link](f)
[Link]([uid,passw])
print("The entry was added to the file successfully")
[Link]()
def search_password(fn,uid):
f = open(fn,'r')
dat = [Link](f)
next(dat)
for i in dat:
if i[0] == str(uid):
print(f"Match Found!!!\nUser ID:{uid}\nPassword:{i[1]}")
break
else:
continue
else:
print("No Record is Found")
[Link]()

while True:
print(".....\[Link] CSV File\n2.Add_Entry\[Link] Password\[Link]\n.....")
ch = int(input("Enter Your Choice:"))
if ch == 1:
fname = input("Enter File Name:")
create_csv(fname)
elif ch ==2:
ui = int(input("Enter User ID:"))
passw = input("Enter Password:")
add_entry(fname,ui,passw)
elif ch == 3:
ui = int(input("Enter User ID to search:"))
search_password(fname,ui)
elif ch == 4:
break
RESULT:
Thus the program was created and executed successfully.
OUTPUT

OUTPUT:
.....
[Link] CSV File
2.Add_Entry
[Link] Password
[Link]
.....
Enter Your Choice:1
Enter File Name:[Link]
The csv file [Link] was created successfully
.....
[Link] CSV File
2.Add_Entry
[Link] Password
[Link]
.....
Enter Your Choice:2
Enter User ID:5
Enter Password:hello
The entry was added to the file successfully
.....
[Link] CSV File
2.Add_Entry
[Link] Password
[Link]
.....
Enter Your Choice:3
Enter User ID to search:5
Match Found!!!
User ID:5
Password:hello
.....
[Link] CSV File
2.Add_Entry
[Link] Password
[Link]
.....
Enter Your Choice:4
16. SQL COMMANDS
CREATING DATABASE:

mysql> create database school;

Accessing DATABASE:

mysql> use school;


Database changed

CREATING TABLE:

create table student(roll_no int,name char(20),gender char(20),grade char(20),marks int);

DESCRIBE TABLE:

desc student;

+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| roll_no | int | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| gender | char(20) | YES | | NULL | |
| grade | char(20) | YES | | NULL | |
| marks | int | YES | | NULL | |
+---------+----------+------+-----+---------+-------+
5 rows in set (0.11 sec)

INSERTING DATA INTO TABLE:


insert into student values(1001,'sa,','male','A1',100);
insert into student values(1002,'arjun,','male','A2',89);
insert into student values(1003,'meera','female','B1',87);

SELECTING ALL DATA:

select * from student;

+---------+--------+--------+-------+-------+
| roll_no | name | gender | grade | marks |
+---------+--------+--------+-------+-------+
| 1003 | meera | female | B1 | 87 |
| 1002 | arjun, | male | A2 | 89 |
| 1001 | sa, | male | A1 | 100 |
+---------+--------+--------+-------+-------+
3 rows in set (0.00 sec)
AGGREGATE FUNCTIONS:

select min(marks) from student;


+------------+
| min(marks) |
+------------+
| 87 |
+------------+
1 row in set (0.02 sec)

select max(marks) from student;


+------------+
| max(marks) |
+------------+
| 100 |
+------------+
1 row in set (0.00 sec)

select sum(marks) from student;


+------------+
| sum(marks) |
+------------+
| 276 |
+------------+
1 row in set (0.00 sec)

select avg(marks) from student;


+------------+
| avg(marks) |
+------------+
| 92.0000 |
+------------+
1 row in set (0.00 sec)

ORDER BY:
select roll_no,marks from student order by marks desc;

+---------+-------+
| roll_no | marks |
+---------+-------+
| 1001 | 100 |
| 1002 | 89 |
| 1003 | 87 |
+---------+-------+
3 rows in set (0.00 sec)

CUSTOMER TABLE:
create table customer(customer_id int,customer_name char(20),country char(20));
insert into customer values(1001,'ram','India');
insert into customer values(1002,'Bama','US');
insert into customer values(1003,'Sam','Africa');
select * from customer;

+-------------+---------------+---------+
| customer_id | customer_name | country |
+-------------+---------------+---------+
| 1001 | ram | India |
| 1002 | Bama | US |
| 1003 | Sam | Africa |
+-------------+---------------+---------+

GROUP BY:
select count(customer_name) from customer group by country;

+----------------------+
| count(customer_name) |
+----------------------+
| 1|
| 1|
| 1|
+----------------------+
3 rows in set (0.00 sec)
17. SIMPLE QUERIES –DOCTOR DATABASE
CREATE DATABASE DOC AND TABLE DOCTOR:
create database doc;

mysql> use doc;

Database changed
CREATE TABLE DOCTOR:
create table doctor(cid int,name char(20),dept char(20),gender char(6),experience
int,cost_fee int);

insert into doctor values(100,'Sam','ENT','Female',30,2000);


insert into doctor values(101,'Divya','Dentist','Male',4,2000);

insert into doctor values(102,'danu','ortho','Female',null,3000);

insert into doctor values(104,'lalli','neuro','Female',6,3000);

select * from doctor;

+------+-------+---------+--------+------------+----------+
| cid | name | dept | gender | experience | cost_fee |
+------+-------+---------+--------+------------+----------+
| 100 | Sam | ENT | Female | 30 | 2000 |
| 101 | Divya | Dentist | Male | 4 | 2000 |
| 102 | Divya | ortho | Female | NULL | 3000 |
| 104 | lalli | neuro | Female | 6 | 3000 |
+------+-------+---------+--------+------------+----------+
4 rows in set (0.00 sec)

select * from doctor;

+------+-------+---------+--------+------------+----------+
| cid | name | dept | gender | experience | cost_fee |
+------+-------+---------+--------+------------+----------+
| 100 | Sam | ENT | Female | 30 | 2000 |
| 101 | Divya | Dentist | Male | 4 | 2000 |
| 102 | danu | ortho | Female | NULL | 3000 |
| 104 | lalli | neuro | Female | 6 | 3000 |
+------+-------+---------+--------+------------+----------+
4 rows in set (0.00 sec)

select name from doctor where experience>10;


+------+
| name |
+------+
| Sam |
+------+
1 row in set (0.00 sec)

select distinct(dept) from doctor;

+---------+
| dept |
+---------+
| ENT |
| Dentist |
| ortho |
| neuro |
+---------+
4 rows in set (0.04 sec)

select min(dept) from doctor;

+-----------+
| min(dept) |
+-----------+
| Dentist |
+-----------+
1 row in set (0.01 sec)

select name,dept from doctor where experience is null;

+------+-------+
| name | dept |
+------+-------+
| danu | ortho |
+------+-------+
1 row in set (0.00 sec)

select avg(cost_fee) from doctor where not gender='Female';

+---------------+
| avg(cost_fee) |
+---------------+
| 2000.0000 |
+---------------+
1 row in set (0.01 sec)

select name,experience from doctor where cid between 100 and 101;

+-------+------------+
| name | experience |
+-------+------------+
| Sam | 30 |
| Divya | 4|
+-------+------------+
2 rows in set (0.00 sec)

select sum(cost_fee),max(experience) from doctor;


+---------------+-----------------+
| sum(cost_fee) | max(experience) |
+---------------+-----------------+
| 10000 | 30 |
+---------------+-----------------+
1 row in set (0.00 sec)
18. SIMPLE QUERIES-LOAN DATABASE
CREATE DATABASE LOANS AND TABLE LOAN-ACCOUNT;
Create database loans;
Use loans;

CREATE TABLE LOAN-ACCOUNTS;

create table loan_account (accno int,cust_name varchar(20),loan_amount int,installments


int,int_rate int,start_date date,interest int);

insert into loan_account values(1,'kyatiGuptay',300000,36,12,'2008-07-19',3600);

insert into loan_account values(2,'sharma',500000,48,10,'2008-03-22',5000);

insert into loan_account values(3,'Deva',300000,36,null,'2007-03-08',3000);

insert into loan_account values(4,'Abhi',800000,60,10,'2008-12-06',8000);

select * from loan_account;

+-------+-------------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-------------+-------------+--------------+----------+------------+----------+
| 1 | kyatiGuptay | 300000 | 36 | 12 | 2008-07-19 | 3600 |
| 2 | sharma | 500000 | 48 | 10 | 2008-03-22 | 5000 |
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | 3000 |
| 4 | Abhi | 800000 | 60 | 10 | 2008-12-06 | 8000 |
+-------+-------------+-------------+--------------+----------+------------+----------+
4 rows in set (0.00 sec)

select accno,cust_name,loan_amount from loan_account;

+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
| 1 | kyatiGuptay | 300000 |
| 2 | sharma | 500000 |
| 3 | Deva | 300000 |
| 4 | Abhi | 800000 |
+-------+-------------+-------------+
4 rows in set (0.00 sec)

Select * from loan_account where installments <40;

+-------+-------------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-------------+-------------+--------------+----------+------------+----------+
| 1 | kyatiGuptay | 300000 | 36 | 12 | 2008-07-19 | 3600 |
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | 3000 |
+-------+-------------+-------------+--------------+----------+------------+----------+
2 rows in set (0.00 sec)

select * from loan_account where start_date <'2011-01-01';

+-------+-------------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-------------+-------------+--------------+----------+------------+----------+
| 1 | kyatiGuptay | 300000 | 36 | 12 | 2008-07-19 | 3600 |
| 2 | sharma | 500000 | 48 | 10 | 2008-03-22 | 5000 |
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | 3000 |
| 4 | Abhi | 800000 | 60 | 10 | 2008-12-06 | 8000 |
+-------+-------------+-------------+--------------+----------+------------+----------+
4 rows in set (0.00 sec)

select cust_name,length(cust_name),lcase(cust_name),ucase(cust_name) from


loan_account where loan_amount <400000;

+-------------+-------------------+------------------+------------------+
| cust_name | length(cust_name) | lcase(cust_name) | ucase(cust_name) |
+-------------+-------------------+------------------+------------------+
| kyatiGuptay | 11 | kyatiguptay | KYATIGUPTAY |
| Deva | 4 | deva | DEVA |
+-------------+-------------------+------------------+------------------+
2 rows in set (0.01 sec)

select left(cust_name,3),right(cust_name,3),substr(cust_name,3) from loan_account where


int_rate >10;

+-------------------+--------------------+---------------------+
| left(cust_name,3) | right(cust_name,3) | substr(cust_name,3) |
+-------------------+--------------------+---------------------+
| kya | tay | atiGuptay |
+-------------------+--------------------+---------------------+
1 row in set (0.01 sec)

select right(cust_name,3),substr(cust_name,5) from loan_account ;


+--------------------+---------------------+
| right(cust_name,3) | substr(cust_name,5) |
+--------------------+---------------------+
| tay | iGuptay |
| rma | ma |
| eva | |
| bhi | |
+--------------------+---------------------+
4 rows in set (0.00 sec)

select dayname(start_date) from loan_account;

+---------------------+
| dayname(start_date) |
+---------------------+
| Saturday |
| Saturday |
| Thursday |
| Saturday |
+---------------------+
4 rows in set (0.00 sec)

select round(int_rate*100/100-2) from loan_account where int_rate >10;

+---------------------------+
| round(int_rate*100/100-2) |
+---------------------------+
| 10 |
+---------------------------+
1 row in set (0.01 sec)

select * from loan_account where loan_amount between 400000 and 500000;

+-------+-----------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-----------+-------------+--------------+----------+------------+----------+
| 2 | sharma | 500000 | 48 | 10 | 2008-03-22 | 5000 |
+-------+-----------+-------------+--------------+----------+------------+----------+
1 row in set (0.00 sec)

select accno,cust_name,loan_amount from loan_account where cust_name like '%shar%';

+-------+-----------+-------------+
| accno | cust_name | loan_amount |
+-------+-----------+-------------+
| 2 | sharma | 500000 |
+-------+-----------+-------------+
1 row in set (0.00 sec)

select accno,loan_amount from loan_account where start_date<'2009-04-01';

+-------+-------------+
| accno | loan_amount |
+-------+-------------+
| 1 | 300000 |
| 2 | 500000 |
| 3 | 300000 |
| 4 | 800000 |
+-------+-------------+
4 rows in set (0.00 sec)

select * from loan_account where int_rate is null;

+-------+-----------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-----------+-------------+--------------+----------+------------+----------+
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | 3000 |
+-------+-----------+-------------+--------------+----------+------------+----------+
1 row in set (0.00 sec)

select count(installments) from loan_account;

+---------------------+
| count(installments) |
+---------------------+
| 4|
+---------------------+
1 row in set (0.00 sec)

select accno,cust_name,loan_amount from loan_account where cust_name like '%a';

+-------+-----------+-------------+
| accno | cust_name | loan_amount |
+-------+-----------+-------------+
| 2 | sharma | 500000 |
| 3 | Deva | 300000 |
+-------+-----------+-------------+
2 rows in set (0.00 sec)
select accno,cust_name,loan_amount from loan_account where cust_name like '%i';

+-------+-----------+-------------+
| accno | cust_name | loan_amount |
+-------+-----------+-------------+
| 4 | Abhi | 800000 |
+-------+-----------+-------------+
1 row in set (0.00 sec)

select * from loan_account order by loan_amount;

+-------+-------------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-------------+-------------+--------------+----------+------------+----------+
| 1 | kyatiGuptay | 300000 | 36 | 12 | 2008-07-19 | 3600 |
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | 3000 |
| 2 | sharma | 500000 | 48 | 10 | 2008-03-22 | 5000 |
| 4 | Abhi | 800000 | 60 | 10 | 2008-12-06 | 8000 |
+-------+-------------+-------------+--------------+----------+------------+----------+
4 rows in set (0.00 sec)

delete from loan_account where start_date <'2007-03-08';

Query OK, 0 rows affected (0.00 sec)

update loan_account set interest =(loan_amount* int_rate*installments)/1200;

Query OK, 4 rows affected (0.04 sec)


Rows matched: 4 Changed: 4 Warnings: 0

select * from loan_account;

+-------+-------------+-------------+--------------+----------+------------+----------+
| accno | cust_name | loan_amount | installments | int_rate | start_date | interest |
+-------+-------------+-------------+--------------+----------+------------+----------+
| 1 | kyatiGuptay | 300000 | 36 | 12 | 2008-07-19 | 108000 |
| 2 | sharma | 500000 | 48 | 10 | 2008-03-22 | 200000 |
| 3 | Deva | 300000 | 36 | NULL | 2007-03-08 | NULL |
| 4 | Abhi | 800000 | 60 | 10 | 2008-12-06 | 400000 |
+-------+-------------+-------------+--------------+----------+------------+----------+
4 rows in set (0.00 sec)
19. QUERIES BASED ON MULTIPLE TABLES
DATABASE: student
TABLES: teacher and teach_salary
Use student;
Show tables;

SHOW RECORDS OF TABLE TEACHER:

select * from teacher;


+------+-----------+----------+------------------------+------------------+
| Tid | firstname | lastname | address | subject |
+------+-----------+----------+------------------------+------------------+
| t010 | Rohit | sharma | 83,lok vihar | English |
| t105 | Meena | Rathi | 842,Rajowri Garden | Computer science |
| t152 | seema | verma | 33,safdariying Emalave | Maths |
| t215 | Sarad | Singh | 440,Ashok vihar | Computer science |
| t244 | Rosy | Ajay | 24,new street | Maths |
| t300 | Ram | Gupta | 9,fifth road ,Delhi | Mother teacher |
+------+-----------+----------+------------------------+------------------+
6 rows in set (0.00 sec)

SHOW RECORDS OF TABLE TEACHSALARY:

select * from teach_salary;


+------+-----------+-------+-------------+
| Tid | gross_sal | bonus | designation |
+------+-----------+-------+-------------+
| t010 | 75000 | 15000 | PGT |
| t105 | 85000 | 15000 | PGT |
| t152 | 60000 | 12000 | TGT |
| t300 | 22000 | 8000 | PRT |
+------+-----------+-------+-------------+
4 rows in set (0.00 sec)

CARTESIAN PRODUCT OF TABLES TEACHER AND TEACHSALARY:


select * from teacher,teach_salary where [Link]=teach_salary.tid;
+------+-----------+----------+------------------------+------------------+------+-----------+-------+-
------------+
| Tid | firstname | lastname | address | subject | Tid | gross_sal | bonus |
designation |
+------+-----------+----------+------------------------+------------------+------+-----------+-------+-
------------+
| t010 | Rohit | sharma | 83,lok vihar | English | t010 | 75000 | 15000 |
PGT |
| t105 | Meena | Rathi | 842,Rajowri Garden | Computer science | t105 | 85000 |
15000 | PGT |
| t152 | seema | verma | 33,safdariying Emalave | Maths | t152 | 60000 | 12000
| TGT |
| t300 | Ram | Gupta | 9,fifth road ,Delhi | Mother teacher | t300 | 22000 | 8000 |
PRT |
+------+-----------+----------+------------------------+------------------+------+-----------+-------+-
------------+
4 rows in set (0.01 sec)

SHOW RECORDS OF TABLE TEACHER AND TEACHSALARY ORDER BY


TID:

select firstname,subject,designation from teacher,teach_salary where


[Link]=teach_salary.tid order by [Link];

+-----------+------------------+-------------+
| firstname | subject | designation |
+-----------+------------------+-------------+
| Rohit | English | PGT |
| Meena | Computer science | PGT |
| seema | Maths | TGT |
| Ram | Mother teacher | PRT |
+-----------+------------------+-------------+
4 rows in set (0.00 sec)

SHOW RECORDS OF TABLE TEACHER AND TEACHSALARY ORDER BY


GROSS_SAL:

select firstname,subject,designation from teacher,teach_salary where


[Link]=teach_salary.tid order by gross_sal;

+-----------+------------------+-------------+
| firstname | subject | designation |
+-----------+------------------+-------------+
| Ram | Mother teacher | PRT |
| seema | Maths | TGT |
| Rohit | English | PGT |
| Meena | Computer science | PGT |
+-----------+------------------+-------------+
4 rows in set (0.00 sec)

SHOW RECORDS OF TABLE TEACHER AND TEACHSALARY GROUP BY


DESIGNATION:
20. QUERIES BASED ON MULTIPLE TABLES-2
DATABASE:

TABLES:

CREATE TABLE STUDENT:

COMMAND TO INSERT 3 RECORDS:

CREATE TABLE SPORT INSIDE CLASS 12 DATABASE:

COMMAND TO INSERT THREE RECORDS:

COMMAND FOR EQUIJOIN OF TABLES:


select [Link],name,game from studnet,sports where
[Link]=[Link];
+-------+---------+----------+
| admno | name | game |
+-------+---------+----------+
| 3712 | suyash | Football |
| 4031 | shiavni | Cricket |
+-------+---------+----------+
2 rows in set (0.01 sec)
COMMAND TO RETRIEVE DATA FROM TWO TABLES:
select name,game from studnet,sports where [Link]=[Link] and
coach_name='Singh';
+---------+----------+
| name | game |
+---------+----------+
| suyash | Football |
| shiavni | Cricket |
+---------+----------+
2 rows in set (0.00 sec)
COMMAND FOR USING GROUP BY CLAUSE IN JOIN:
select avg(marks),grade from studnet,sports where [Link]=[Link]
group by grade;
+------------+-------+
| avg(marks) | grade |
+------------+-------+
| 67.0000 | B |
| 97.0000 | A |
+------------+-------+
2 rows in set (0.00 sec)
COMMAND FOR USING GROUP BY AND ORDER BY CLAUSE IN EQUI JOIN:
COMMAND FOR USING WHERE CLAUSE AND GROUP BY:

COMMAND FOR ADDING PIMARY KEY:


alter table sports add primary key (admno);
COMMAND TO DELETE A COLUMN:
alter table studnet drop rno;
Query OK, 0 rows affected (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 0
COMMAND TO DROP PRIMARY KEY COSNTRINT FROM THE TABLE
STUDENT:
alter table studnet drop primary key;
Query OK, 3 rows affected (0.61 sec)
Records: 3 Duplicates: 0 Warnings: 0

COMMAND TO INCREASE MARKS:


update student set marks=marks+10;
COMMAND TO CHAnGE DATA TYPE OF AN EXISTING COLUMN:
alter table studnet modify marks decimal(8,2);
Query OK, 3 rows affected (1.43 sec)
Records: 3 Duplicates: 0 Warnings: 0
COMMAND TO DELETE A TABLE:
drop table studnet;
Query OK, 0 rows affected (0.43 sec)

21. STUDENT DETAILS


AIM:
The aim of the program is to retrieve details of the student from mysql database.
ALGORITHM:
Step 1: Start the program
Step 2: Include all necessary header files.
Step 3: Establish connection to the database by giving hostname, username, password and
database name.
Step 4: Create cursor object.
Step 5: Execute the query.
Step 6: Using fetch all command retrieve all the details of all students stored in the database
school.
Step 7:Print the data.
Step 8:End the program
CODE:
import [Link] as sqltor
mycon=[Link](host='localhost',user='root',passwd='valab2',database='school')
mycursor=[Link]()
[Link]("select*from student;")
data=[Link]()
while data is not None:
print(data)
data=[Link]()
[Link]()
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
[('CSK7829', 'Coimbatore', 'Chennai', [Link](2025, 9, 6), '12:21'),
('KRR5490', 'Delhi', 'Ahmedabad', [Link](2025, 9, 6), '12:34'),
('PBKS837', 'Ahmedabad', 'Hyderabad', [Link](2025, 9, 6), '12:34')]
22. EMPLOYEE MANAGEMENT SYSTEM-INSERT
AIM:
The aim of the program is to insert and delete the details of the employee in MYSQL
database.

ALGORITHM:
Step 1: Start the program
Step 2: Include all necessary header files.
Step 3: Establish connection to the database by giving hostname, username, password and
database name.
Step 4: Create cursor object.
Step 5: Execute the query.
Step 6: Create buttons for insert and exit.
Step 7: End the program

CODE:
from tkinter import*
import [Link] as sqltor
def newone():
[Link](0,END)
[Link](0,END)
[Link](0,END)
[Link](0,END)
[Link](0,END)
[Link](0,END)
a=Tk()

Label(a,text='Empid').grid(row=0)
txtEmpid=Entry(a)
[Link](row=0,column=1)

Label(a,text='Jobid').grid(row=1)
txtJobid=Entry(a)
[Link](row=1,column=1)
Label(a,text='Name').grid(row=2)
txtName=Entry(a)
[Link](row=2,column=1)

Label(a,text='Sales').grid(row=3)
txtSales=Entry(a)
[Link](row=3,column=1)

Label(a,text='Jobtitle').grid(row=4)
txtJobtitle=Entry(a)
[Link](row=4,column=1)

Label(a,text='Salary').grid(row=5)
txtSalary=Entry(a)
[Link](row=5,column=1)

Button(a,text="New enteries",command=newone).grid(row=6,column=0)
sbl=Scrollbar(a)
[Link](row=8,column=1)
def insert():
a=[Link]()
b=[Link]()
c=[Link]()
d=[Link]()
e=[Link]()
f=[Link]()
mycon=[Link](host='localhost',user='root',passwd='valab2',database='School')
mycursor=[Link]()
[Link]("Insert into employee values(%s,%s,%s,%s,%s,%s"),(a,b,c,d,e,f)
[Link]()
Button(a,text='Save',command='insert').grid(row=6,column=1)
Button(a,text='Exit',command=quit).grid(row=6,column=3)

RESULT:
Thus the program was created and executed successfully.

OUTPUT:
23. EMPLOYEE MANAGEMENT SYSTEM-DELETE
AIM:
The aim of the program is to delete the details of employee in MYSQL database.
ALGORITHM:
Step 1: Start the program
Step 2: Include all necessary header files.
Step 3: Establish connection to the database by giving hostname, username, password and
database name.
Step 4: Create cursor object.
Step 5: Execute the query.
Step 6: Create buttons for delete and exit.
Step 7: End the program

CODE:

from tkinter import*

import [Link] as sqltor


def deletemore():
[Link](0,END)
a=Tk()
Label(a,text='Empid').grid(row=0)
txtEmpid=Entry(a)
[Link](row=0,column=1)
sbl=Scrollbar(a)
[Link](row=8,column=1)
def delete():
a=[Link]()
mycon=[Link](host='localhost',user='root',passwd='valab2',database='School')
mycursor=[Link]()
[Link]("Delete from employee where empid=%;",(a))
[Link]()
[Link]()
Button(a,text='delete more',command=deletemore).grid(row=6,column=0)
Button(a,text='delete',command=delete).grid(row=6,column=1)
Button(a,text='Exit',command=quit).grid(row=6,column=3)

RESULT:
Thus the program was created and executed successfully.

OUTPUT:

24. PLAYER DETAILS


AIM:
The aim of the program is to update details of the palyers from MYSQL database.

ALGORITHM:
Step 1: Start the program
Step 2: Include all necessary header files.
Step 3: Establish connection to the database by giving hostname, username, password and
database name.
Step 4: Create cursor object.
Step 5: Execute the query.
Step 6: Using update command update the values of specific player Id
Step 7: Print records are updated .
Step 8: End the program
CODE:
import [Link] as sqltor
mycon=[Link](host='localhost',user='root',password='valab2',database='players')
mycursor=[Link]()
ch='y'
while ch=='y':
print('[Link] EDIT THE PLAYER NAME')
print('[Link] EDIT THE GAME')
print('[Link] EDIT THE GENDER')
print('[Link] EDIT THE REGION')
i=input('Enter the Option:')
if i=='1':
name=input('Enter the New Name:')
old=int(input('Enter the Playerid:'))
query='update player set name="{}" where playerid="{}"'.format(name,old)
[Link](query)
if i=='2':
game=input('Enter the New Game:')
old=int(input('Enter the Playerid:'))
query='update player set game="{}" where playerid="{}"'.format(game,old)
[Link](query)
if i=='3':
gn=input('Enter the New Gender:')
old=int(input('Enter the Playerid:'))
query='update player set gender="{}" where playerid="{}"'.format(gn,old)
[Link](query)
if i=='4':
reg=input('Enter the New Region:')
old=int(input('Enter the Playerid:'))
query='update player set region="{}" where playerid="{}"'.format(reg,old)
[Link](query)
print('Succefully Changed')
ch=input('Do you want to Continue(y/n):')
if ch=='y':
continue
else:
break
[Link]()
[Link]()

RESULT:
Thus the program was created and executed successfully.
OUTPUT:
[Link] EDIT THE PLAYER NAME
[Link] EDIT THE GAME
[Link] EDIT THE GENDER
[Link] EDIT THE REGION
Enter the Option:1
Enter the New Name:niriksha
Enter the Playerid:12
Succefully Changed
Do you want to Continue(y/n):y
[Link] EDIT THE PLAYER NAME
[Link] EDIT THE GAME
[Link] EDIT THE GENDER
[Link] EDIT THE REGION
Enter the Option:2
Enter the New Game:cricket
Enter the Playerid:78
Succefully Changed
Do you want to Continue(y/n):y
[Link] EDIT THE PLAYER NAME
[Link] EDIT THE GAME
[Link] EDIT THE GENDER
[Link] EDIT THE REGION
Enter the Option:3
Enter the New Gender:male
Enter the Playerid:12
Succefully Changed
Do you want to Continue(y/n):y
[Link] EDIT THE PLAYER NAME
[Link] EDIT THE GAME
[Link] EDIT THE GENDER
[Link] EDIT THE REGION
Enter the Option:4
Enter the New Region:chennai
Enter the Playerid:12
Succefully Changed
Do you want to Continue(y/n):n

You might also like