XII Practical Programs
XII Practical Programs
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
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
65 7
print("REPLICATING OPERATOR")
x=input("Enter a value:")
print(x*2)
print("CONCATENATION OPERATOR")
y=input("Enter a value:")
print(y+z)
print("MEMBERSHIP OPERATOR")
if b in a:
print("TRUE")
else:
print("FALSE")
if d not in c:
print("TRUE")
else:
print("FALSE")
print("COMPARISION OPERATOR")
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
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:
Accessing DATABASE:
CREATING TABLE:
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)
+---------+--------+--------+-------+-------+
| 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:
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;
Database changed
CREATE TABLE DOCTOR:
create table doctor(cid int,name char(20),dept char(20),gender char(6),experience
int,cost_fee int);
+------+-------+---------+--------+------------+----------+
| 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)
+------+-------+---------+--------+------------+----------+
| 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)
+---------+
| dept |
+---------+
| ENT |
| Dentist |
| ortho |
| neuro |
+---------+
4 rows in set (0.04 sec)
+-----------+
| min(dept) |
+-----------+
| Dentist |
+-----------+
1 row in set (0.01 sec)
+------+-------+
| name | dept |
+------+-------+
| danu | ortho |
+------+-------+
1 row in set (0.00 sec)
+---------------+
| 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)
+-------+-------------+-------------+--------------+----------+------------+----------+
| 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)
+-------+-------------+-------------+
| accno | cust_name | loan_amount |
+-------+-------------+-------------+
| 1 | kyatiGuptay | 300000 |
| 2 | sharma | 500000 |
| 3 | Deva | 300000 |
| 4 | Abhi | 800000 |
+-------+-------------+-------------+
4 rows in set (0.00 sec)
+-------+-------------+-------------+--------------+----------+------------+----------+
| 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)
+-------+-------------+-------------+--------------+----------+------------+----------+
| 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)
+-------------+-------------------+------------------+------------------+
| 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)
+-------------------+--------------------+---------------------+
| left(cust_name,3) | right(cust_name,3) | substr(cust_name,3) |
+-------------------+--------------------+---------------------+
| kya | tay | atiGuptay |
+-------------------+--------------------+---------------------+
1 row in set (0.01 sec)
+---------------------+
| dayname(start_date) |
+---------------------+
| Saturday |
| Saturday |
| Thursday |
| Saturday |
+---------------------+
4 rows in set (0.00 sec)
+---------------------------+
| round(int_rate*100/100-2) |
+---------------------------+
| 10 |
+---------------------------+
1 row in set (0.01 sec)
+-------+-----------+-------------+--------------+----------+------------+----------+
| 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)
+-------+-----------+-------------+
| accno | cust_name | loan_amount |
+-------+-----------+-------------+
| 2 | sharma | 500000 |
+-------+-----------+-------------+
1 row in set (0.00 sec)
+-------+-------------+
| accno | loan_amount |
+-------+-------------+
| 1 | 300000 |
| 2 | 500000 |
| 3 | 300000 |
| 4 | 800000 |
+-------+-------------+
4 rows in set (0.00 sec)
+-------+-----------+-------------+--------------+----------+------------+----------+
| 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)
+---------------------+
| count(installments) |
+---------------------+
| 4|
+---------------------+
1 row in set (0.00 sec)
+-------+-----------+-------------+
| 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)
+-------+-------------+-------------+--------------+----------+------------+----------+
| 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)
+-------+-------------+-------------+--------------+----------+------------+----------+
| 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;
+-----------+------------------+-------------+
| firstname | subject | designation |
+-----------+------------------+-------------+
| Rohit | English | PGT |
| Meena | Computer science | PGT |
| seema | Maths | TGT |
| Ram | Mother teacher | PRT |
+-----------+------------------+-------------+
4 rows in set (0.00 sec)
+-----------+------------------+-------------+
| firstname | subject | designation |
+-----------+------------------+-------------+
| Ram | Mother teacher | PRT |
| seema | Maths | TGT |
| Rohit | English | PGT |
| Meena | Computer science | PGT |
+-----------+------------------+-------------+
4 rows in set (0.00 sec)
TABLES:
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:
RESULT:
Thus the program was created and executed successfully.
OUTPUT:
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