0% found this document useful (0 votes)
88 views49 pages

Xii Record Note 2025-26

The document outlines a series of programming experiments aimed at demonstrating various coding concepts, including generating Fibonacci series, checking for palindromes, and calculating areas of shapes. Each experiment includes a program, sample input and output, and a confirmation of successful execution. The experiments also cover file handling, dictionary usage, and exception handling in Python.

Uploaded by

fenics2626
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)
88 views49 pages

Xii Record Note 2025-26

The document outlines a series of programming experiments aimed at demonstrating various coding concepts, including generating Fibonacci series, checking for palindromes, and calculating areas of shapes. Each experiment includes a program, sample input and output, and a confirmation of successful execution. The experiments also cover file handling, dictionary usage, and exception handling in Python.

Uploaded by

fenics2626
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

Exp.

No: 01 Fibonacci Series


Date: 11-04-2025

Aim: To print Fibonacci Series using function

Program:

def Fibonacci(n):

firsterm = -1
secondterm = 1
for i in range(n):
thirdterm = firsterm + secondterm
print(thirdterm,end = " ")
firsterm = secondterm
secondterm = thirdterm
print("Fibonacci Series")
n = int(input("Enter the number of terms you want to print: ")) Fibonacci(n)

Sample Input and Output:


Fibonacci Series
Enter the number of terms you want to print: 10 0 1 1 2 3 5 8 13 21 34

Result: The above program has been executed successfully

1
[Link]: 02 Palindrome
Date: 25-04-2025

Aim: To check whether a given string is a palindrome or not.

Program:

def Palindrome(myLength):
for i in (0,myLength//2):
if myString[i] != myString[myLength-i-1]:
print("The given string",myString," is not a Palindrome")
break
else:
continue
else:
print("The given string",myString," is a Palindrome")

print("Palindrome Check")
myString = input("Enter a string: ")
myLength = len(myString)
Palindrome(myLength)

Sample Input and Output:

Palindrome Check
Enter a string: Madam
The given string Madam is not a Palindrome

Palindrome Check
Enter a string: MalayalaM
The given string MalayalaM is a Palindrome

Result: The above program has been executed successfully

2
[Link]: 03 Printing the largest and smallest country name in the list
Date: 06-06-2025

Aim: To create a list with different country names and print the largest and the
smallest country (by counting the number of characters) using function.

Program:

def MaxMin(n):
Country = []
for i in range(n):
cname = input('Enter the country name: ')
[Link](cname)
[Link](key=len)
print('Country with the smallest length = ',Country[0])
print('Country with the largest length = ',Country[-1])
n = int(input('Enter the no. of country: '))
MaxMin(n)

Sample Input and Output:

Enter the no. of country: 5


Enter the country name: Japan
Enter the country name: Canada
Enter the country name: Srilanka
Enter the country name: USA
Enter the country name: Russia
Country with the smallest length = USA Country with the largest length = Srilanka

Result: The above program has been executed successfully

3
[Link]: 04 Menu driven program to calculate area of different shapes
Date: 13-06-2025

Aim: To develop a menu driven program to calculate the area of different


shapes using functions.

Program:

def Area(Choice): if Choice == 1:


side = int(input('Enter your side value: '))
areasq = side * side
print('Area of a square = ',areasq)
elif Choice == 2:
length = int(input('Enter the Length value: '))
breadth = int(input('Enter the Breadth value: '))
arearec = length * breadth
print('Area of a rectangle = ',arearec)
elif Choice == 3:
base = int(input('Enter the base value: '))
height = int(input('Enter the height value: '))
areatri = 0.5 * base * height
print('Area of a triangle = ',areatri)
elif Choice == 4:
exit
print('Menu Driven Program to Compute the Area of different shapes')
print(' ')
print('1. To compute area of a square')
print('2. To compute area of a rectangle')
print('3. To compute area of a triangle')
print('4. Exit')
Choice = int(input('Enter your choice between 1 to 4: '))
if Choice < 1 or Choice > 4:
print('Wrong Choice')
else:
Area(Choice)

4
Sample Input and Output:
Menu Driven Program to Compute the Area of different shapes

1. To compute area of a square


2. To compute area of a rectangle
3. To compute area of a triangle
4. Exit
Enter your choice between 1 to 4: 1 Enter your side value: 10
Area of a square = 100
Menu Driven Program to Compute the Area of different shapes

1. To compute area of a square


2. To compute area of a rectangle
3. To compute area of a triangle
4. Exit
Enter your choice between 1 to 4: 2 Enter the Length value: 20
Enter the Breadth value: 30 Area of a rectangle = 600
Menu Driven Program to Compute the Area of different shapes

1. To compute area of a square


2. To compute area of a rectangle
3. To compute area of a triangle
4. Exit
Enter your choice between 1 to 4: 3 Enter the base value: 25
Enter the height value: 50 Area of a triangle = 625.0
Menu Driven Program to Compute the Area of different shapes

1. To compute area of a square


2. To compute area of a rectangle
3. To compute area of a triangle
4. Exit
Enter your choice between 1 to 4: 4
Menu Driven Program to Compute the Area of different shapes

1. To compute area of a square


2. To compute area of a rectangle

5
3. To compute area of a triangle
4. Exit

Enter your choice between 1 to 4: 56


Wrong Choice

Result: The above program has been executed successfully

6
[Link]: 05 Search and display using dictionary
Date: 26-06-2025

Aim: To create a dictionary to store roll number and name of 5 students, for a given
roll number display the corresponding name else display appropriate error message.

Program:
myDict = {}
def InputDictionary():
for i in range(5):
rno = int(input('Enter the rollno: '))
name = input('Enter the name: ')
myDict[rno] = name
print(myDict)

def Search(n):
found = 0
for i in myDict:
if i == n:
found = 1
print('The element is found')
print(i,' ',myDict[i])
break
if found == 0:
print(n,' is not found in the dictionary')

InputDictionary()
n = int(input('Enter the key to be searched: '))
Search(n)

7
Sample Input and Output:

Enter the rollno: 1


Enter the name: a
Enter the rollno: 2
Enter the name: b
Enter the rollno: 3
Enter the name: c
Enter the rollno: 4
Enter the name: d
Enter the rollno: 5
Enter the name: e
{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}

Enter the key to be searched: 3


The element is found
3 c

Enter the rollno: 1


Enter the name: a
Enter the rollno: 2
Enter the name: b
Enter the rollno: 3
Enter the name: c
Enter the rollno: 4
Enter the name: d
Enter the rollno: 5
Enter the name: e
{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}
Enter the key to be searched: 32
32 is not found in the dictionary

Result: The above program has been executed successfully

8
[Link]: 06 Division Calculator (Exception Handling)
Date: 04-07-2025

Aim: To generate random numbers between 1 to 6 (stimulate a dice)

Program:

def divide_numbers():

try:

num1 = int(input("Enter the numerator: "))

num2 = int(input("Enter the denominator: "))

result = num1 / num2

print(f"Result: {result}")

except ZeroDivisionError:

print("Error: Cannot divide by zero.")

except ValueError:

print("Error: Please enter valid integers.")

finally:

print("Execution completed.")

# Run the function

divide_numbers()

9
Sample Input and Output:

Enter the numerator: 8


Enter the denominator: 2
Result: 4.0
Execution completed.

Enter the numerator: 8


Enter the denominator: 0
Error: Cannot divide by zero.
Execution completed.

Result: The above program has been executed successfully

10
[Link]: 07 Read a text file line by line and print # after each word
Date: 10-07-2025

Aim: To read a text file, line by line and display each word separated by ‘#’

Program:

def Line2WordaddHash():
with open('[Link]') as F:
Lines = [Link]()
myList = []
for i in Lines:
myList = [Link]()
for j in myList:
print(j,"#",end= " ")
Line2WordaddHash()

Sample Input and Output:

[Link]

This # is # my # first # text # file # This # is # my # second # line # India # is # my #


mother # land # I # love # my # country #

Result: The above program has been executed successfully

11
[Link]: 08 Printing all the lines starting with ‘T’
Date: 17-07-2025

Aim: To read a text file and print all the lines that are starting with ‘T’ on the screen

Program:

def PrintSpecificLines():
with open('[Link]') as F:
Reader = [Link]()
for line in Reader:
if line[0] == 'T':
print(line)
PrintSpecificLines()

Sample Input and Output:

[Link]

This is my first text file

This is my second line

Result: The above program has been executed successfully

12
[Link]: 09 Counting the number of occurrences
Date: 25-07-2025 of ‘is’ and ‘and ‘ in a text file

Aim: To read a text file and count the number of occurrences of ‘is’ and ‘and’ in that
file.

Program:

def Countisand():
with open('[Link]','r') as rfile:
Reader = [Link]()
print(Reader)
count = 0
for line in Reader:
words = [Link]()
for i in words:
if i == 'is' or i == 'and':
count+=1
print('The total no. of words with is / and = ',count)
Countisand()

Sample Input and Output:

['This is my sample text file program to count the number of occurrences of is and and
present in this text file.']
The total no. of words with is / and = 4

Result: The above program has been executed successfully

13
[Link]: 10 Counting vowels, consonants, digits, And special characters,
Date: 05-08-2025 lower case & upper case letters present in a text file.

Aim: To count the number of vowels, consonants, digits, special characters, lower
case & upper case letters present in a text file and display the same.

Program:

def TextFileCounting():
ucase = 0
lcase = 0
vowels = 0
consonants = 0
digits = 0
special = 0
with open('[Link]') as rtextfile:
Read = [Link]()
for ch in Read:
if [Link]():
if ch in ['a','e','i','o','u','A','E','I','O','U']:
vowels+=1
else:
consonants+=1
if [Link]():
ucase+=1
if [Link]():
lcase+=1
elif [Link]():
digits+=1
else:
special+=1
print('No of uppercase alphabets = ',ucase)
14
print('No of lowercase alphabets = ',lcase)
print('No of digits = ',digits)
print('No of vowels = ',vowels)
print('No of consonants = ',consonants)
print('No of special characters = ',special)
TextFileCounting()

Sample Input and Output:


No of uppercase alphabets = 7
No of lowercase alphabets = 164
No of digits = 2
No of vowels = 63
No of consonants = 108
No of special characters = 40

Result: The above program has been executed successfully


15
[Link]: 11 To read a text file and create a new file after adding “ing”
Date: 14-08-2025 to all words ending with ‘s’ and ‘d’:

Aim: To read a text file and create a new file after adding “ing” to all words ending
with ‘s’ and ‘d’

Program:

def Adding_ing():
with open('[Link]','r') as rfile:
with open('Mywordfilewith_ing.txt','w') as wfile:
Reader = [Link]()
print(Reader)

for line in Reader:


words = [Link]()
for i in words:
if i[-1] == 's' or i[-1] == 'd':
i = i + 'ing'
[Link](i)
with open('Mywordfilewith_ing.txt','r') as wfile:
Reader = [Link]()
print(Reader)

Adding_ing()

Sample Input and Output:

['This is my sample text file program to count the number of occurrences of is and and
present in this text file.']
['Thisingisingmysampletextfileprogramtocounthenumberofoccurrancesingofisingandingan
din gpresentinthisingtextfile.']

Result: The above program has been executed successfully


16
[Link]: 12 csv Files
Date: 22-08-2025 Storing and retrieving student’s information using csv file

Aim: To store and retrieve student’s information using csv file.

Program:
import csv stu = []
def write_csv_data():
with open('[Link]','a',newline='') as F:
Write = [Link](F)
ch = 'y'
while ch == 'y':
name = input('Enter the student name:')
totalmarks = int(input('Total marks:'))
stu = [name,totalmarks]
[Link](stu)
ch = input('Do you want to continue y/n: ')

def read_csv_data():
with open('[Link]','r') as F:
Reader = [Link](F)
for Data in Reader:
print(Data[0],int(Data[1]),int(Data[1])/5)
write_csv_data()
read_csv_data()

17
Sample Input and Output:

Enter the student name: Kayal


Total marks: 475
Do you want to continue y/n: y
Enter the student name: Avinash
Total marks:445
Do you want to continue y/n: n
abc 450 90.0
bcd 455 91.0
cde 460 92.0
def 465 93.0
Senthil 440 88.0
Abi 400 80.0
Harini 415 83.0
Hari 400 80.0
Sundar 425 85.0
Senthil 375 75.0
Abirami 350 70.0
Guna 300 60.0
Abishek 275 55.0
Kayal 475 95.0
Avinash 445 89.0

Result: The above program has been executed successfully

18
[Link]: 13 Copying the contents of one csv file to another
Date: 29-08-2025 using different delimiter

Aim: To copy the contents of a csv file into another file using different delimiter

Program:

import csv
def copy_csv_data():
with open('[Link]') as F1:
with open('[Link]','w',newline='') as F2:
Read = [Link](F1)
Write = [Link](F2,delimiter= '#')
for line in Read:
[Link](line)
def display_copied_data():
with open('[Link]') as F:
Reader = [Link](F)
for Data in Reader:
print(Data)
copy_csv_data()
display_copied_data()

Sample Input and Output:

['100#Hamam#28']
['101#Cinthol#29']
['102#Dove#45']

Result: The above program has been executed successfully

19
[Link]: 14 Binary Files - Search and display using binary file
Date: 04-09-2025

Aim: To create a binary file to store member no and member name. Given a member
no, display its associated name else display appropriate error message.

Program:

import pickle Member = {}

def Store_binary_info():
with open('[Link]','ab') as wbfile:
while True:
Mno = int(input('Enter the member no: '))
name = input('Enter the name: ')
Member['MemberNo'] = Mno
Member['Name'] = name
[Link](Member,wbfile)
ch = input('Do you want to continue y/n :')
if ch == 'n':
print('Binary File writing is over')
break
def Search_display_binary_info():
with open('[Link]','rb') as rbfile:
mno = int(input('Enter the member no to be searched:'))
try:
while True:
Member = [Link](rbfile)
if Member['MemberNo'] == mno:
print(Member)
break
except EOFError:
print('MemberNo not found')
20
Store_binary_info()
Search_display_binary_info()
Search_display_binary_info()

Sample Input and Output:

Enter the member no: 8002

Enter the name: Sukanya


Do you want to continue y/n :y

Enter the member no: 8003

Enter the name: Archana


Do you want to continue y/n :y
Enter the member no: 8004 Enter the name: Prasath
Do you want to continue? y/n :n
Binary File writing is over
Enter the member no to be searched:8003
{'MemberNo': 8003, 'Name': 'Archana'}
Enter the member no to be searched:8008
Member No not found

Result: The above program has been executed successfully

21
[Link]: 15 Menu driven program to write/read/update
Date: 11-09-2025 and append data on to binary file

Aim: To create a menu driven program to write, read, update and append data on to a
binary file.

Program:

import pickle

Member = {}

def Writing_Binary():
with open('[Link]','wb') as wbfile:
while True:
Mno = int(input('Enter the member no: '))
name = input('Enter the name: ')
Member['MemberNo'] = Mno
Member['Name'] = name
[Link](Member,wbfile)
ch = input('Do you want to continue y/n :')
if ch == 'n':
print('Binary File writing is over')
break

def Read_Display_Binary():
with open('[Link]','rb') as rbfile:
try:
while True:
Member = [Link](rbfile)
print(Member)
except EOFError:
print('Finished reading binary file')

def Update_Binary():
found = False

22
with open('[Link]','rb+') as rbfile:
try:
while True:
rpos = [Link]()
Member = [Link](rbfile)
if Member['Name'] == 'Sundar':
Member['Name'] = 'Sundari'
[Link](rpos)
[Link](Member,rbfile)

print(Member)

found = True

break
except EOFError:
if found == False:
print('Data not updated in the file')
else:
print('Data updated successfully')
def Append_Binary():
with open('[Link]','ab') as wbfile:
while True:
Mno = int(input('Enter the member no: '))
name = input('Enter the name: ')
Member['MemberNo'] = Mno
Member['Name'] = name
[Link](Member,wbfile)
ch = input('Do you want to continue y/n :')
if ch == 'n':
print('Binary File writing is over')
break
while True:
print(' ')
print('Menu Driven Programming')
print(' ')

23
print('1. To create and store binary data')
print('2. To read the binary data')
print('3. To update the binary data')
print('4. To append data to the binary file')
print('5. To exit')
ch = int(input('Enter your choice: '))
if ch == 1:
Writing_Binary()
elif ch == 2:
Read_Display_Binary()
elif ch == 3:
Update_Binary()
elif ch == 4:
Append_Binary()
elif ch == 5:
break

Sample Input and Output:

Menu Driven Programming

1. To create and store binary data


2. To read the binary data
3. To update the binary data
4. To append data to the binary file
5. To exit
Enter your choice: 1
Enter the member no: 101
Enter the name: Senthil
Do you want to continue y/n :y
Enter the member no: 102
Enter the name: Arun
Do you want to continue y/n :y
Enter the member no: 103
Enter the name: Dharshini
Do you want to continue y/n :n
Binary File writing is over

24
Menu Driven Programming

1. To create and store binary data


2. To read the binary data
3. To update the binary data
4. To append data to the binary file
5. To exit
Enter your choice: 4
Enter the member no: 104
Enter the name: Akash
Do you want to continue y/n :y
Enter the member no: 105
Enter the name: Sundar
Do you want to continue y/n :n
Binary File writing is over

Menu Driven Programming

1. To create and store binary data


2. To read the binary data
3. To update the binary data
4. To append data to the binary file
5. To exit
Enter your choice: 2
{'MemberNo': 101, 'Name': 'Senthil'}
{'MemberNo': 102, 'Name': 'Arun'}
{'MemberNo': 103, 'Name': 'Dharshini'}
{'MemberNo': 104, 'Name': 'Akash'}
{'MemberNo': 105, 'Name': 'Sundar'} Finished reading binary file

Menu Driven Programming

1. To create and store binary data


2. To read the binary data
3. To update the binary data
4. To append data to the binary file
5. To exit
Enter your choice: 3
{'MemberNo': 105, 'Name': 'Sundari'}

25
Menu Driven Programming

1. To create and store binary data


2. To read the binary data
3. To update the binary data
4. To append data to the binary file
5. To exit
Enter your choice: 5

Result: The above program has been executed successfully

26
[Link]: 16 Stack operation
Date: 25-09-2025

Write a Python program to implement a stack using a list data-structure.

Aim: To implement the stack operation using a list data structure

Program:

stack=[ ]

def view( ):

for x in range(len(stack)):

print(stack[x])

def push( ):

item=int(input("Enter integer value"))

[Link](item)

def pop( ):

if(stack= =[ ]):

print("Stack is empty")

else:

item=[Link](-1)

print("Deleted element:",item)

def peek( ):

item=stack[-1]

print("Peeked element:",item)

print("Stack operation")

print("************")

print("[Link]")

print("[Link]")

print("[Link]")

print("[Link]") while True:

choice=int(input("Enter your choice"))

27
if choice= =1:

view( )

elif choice= =2:

push( )

elif choice==3:

pop( )

elif choice= =4:

peek( )

else:

print("Wrong choice")

Output:

Stack operation

************

1. view

2. push

3. pop

4. peek

Enter your choice2

Enter integer value56

Enter your choice2

Enter integer value78

Enter your choice2

Enter integer value90

Enter your choice1

56

78

90

28
Enter your choice4

Peeked element: 90

Enter your choice3

Deleted element: 90

Enter your choice1

5678

Enter your choice4

Peeked element: 78

Enter your choice5

Wrong choice

Result:

Thus the given program executed successfully

29
[Link]: 17 Stationary and consumer
Date: 30-09-2025

Aim: To create two tables for stationary and consumer and execute the given commands
using SQL.

TABLE: STATIONARY

S_ID StationaryName Company Price

DP01 Dot Pen ABC 10

PL02 Pencil XYZ 6

ER05 Eraser XYZ 7

PL01 Pencil CAM 5

GP02 Gel Pen ABC 15

TABLE: CONSUMER

C_ID ConsumerName Address S_ID

01 Good Learner Delhi PL01

06 Write Well Mumbai GP02

12 Topper Delhi DP01

15 Write & Draw Delhi PL02

16 Motivation Bangalore PL01

i) To display the details of those Consumers whose Address is Delhi

ii) To display the details of Stationary whose Price is in the range of 8 to 15

(Both values included)

iii) To display the ConsumerName , Address from table Consumer and Company and
Price from table Stationery with their corresponding matching S_ID

iv) To increase the Price of all Stationary by 2.

v) To display distinct Company from STATIONARY .

30
Output:

i) select * from consumer where address=”delhi”;

C_ID Consumer Name Address S_ID

1 good learner delhi PL01

12 topper delhi DP02

15 write & draw delhi PL02

ii) select * from stationary where price between 8 and 15;

S_ID StationaryName Company Price

Dp01 dot pen ABC 10

GP02 gel pen ABC 15

iii) select consumername, address, company, price from stationery, consumer where
stationery.s_id=consumer.s_id;

Consumer Name Address Company Price

good learner delhi CAM 5

write well mumbai ABC 15

topper delhi ABC 10

write&draw delhi XYZ 6

motivation bangalore CAM 5

iv) update stationery set price=price+2; select * from stationery;

S_ID StationaryName Company Price

DP01 Dot pen ABC 12

PL02 Pencil XYZ 8

ER05 Eraser XYZ 9

PL01 Pencil CAM 7

31
GP02 Gel pen ABC 17

v) select distinct(company) from stationery;

Company

ABC

XYZ

CAM

32
[Link]: 18 Item and traders
Date: 03-10-2025

Aim: To create two tables for item and traders and execute the given commands using
SQL.

TABLE: ITEM

Code IName Qty Price Company TCode

1001 DIGITAL PAD 121 120 11000 XENTIA T01

1006 LED SCREEN 40 70 38000 SANTORA T02

1004 CAR GPS SYSTEM 50 2150 GEOKNOW T01

1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02

1005 PEN DRIVE 32GB 600 1200 STOREHOME T03

TABLE:TRADERS

TCode TName City

T01 ELECTRONICS SALES MUMBAI

T03 BUSY STORE CORP DELHI

T02 DISP HOUSE INC CHENNAI

i) To display the details of all the items in ascending order of item names (i.e
IName)

ii) To display item name and price of all those items, whose price is in the range
of 10000 and 22000 (both values inclusive)

iii) To display the number of items, which are traded by each trader. The expected
output of this query should be
T01 2
T02 2
T03 1

iv) To display the Price, item name (i.e IName) and quantity (i.e Qty) of those
items which have quantity more than 150.

v) To display the names of those traders, who are either from DELHI or from
MUMBAI?

33
Output:

i) select * from ITEM order by IName;

Code IName Qty Price Company TCode

1004 CAR GPS SYSTEM 50 2150 GEOKNOW T01

1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02

1001 DIGITAL PAD 121 120 11000 XENTIA T01

1006 LED SCREEN 70 38000 SANTORA T02

1005 PEN DRIVE 32GB 600 1200 STORE T03


HOME

ii) select IName , Price from ITEM where Price between 10000 and 22000;

IName Price

DIGITAL PAD 121 11000

iii) select TCode , count(*) from ITEM group by TCode;

Tcode Count(*)

T01 2

T02 2

T03 1

iv) select Price , IName , Qty from ITEM where Qty>150;

Price IName Qty

8000 DIGITAL CAMERA 12X 160

1200 PEN DRIVE 32GB 600

v) select TName from TRADERS where City in (“DELHI”,”MUMBAI”);

TName

ELECTRONICS SALES

BUSY STORE CORP

34
[Link]: 19 Doctor and salary
Date: 09-10-2025

Aim: To create two tables for doctor and salary and execute the given commands using

SQL.

TABLE:DOCTOR

ID NAME DEPT SEX EXPERIENCE

101 John ENT M 12

104 Smith ORTHOPEDIC M 5

107 George CARDIOLOGY M 10

114 Lara SKIN F 3

109 K George MEDICINE F 9

105 Johnson ORTHOPEDIC M 10

117 Lucy ENT F 3

111 Bill MEDICINE F 12

130 Morphy ORTHOPEDIC M 15

TABLE: SALARY

ID BASIC ALLOWANCE CONSULTATION

101 12000 1000 300

104 23000 2300 500

107 32000 4000 500

114 12000 5200 100

109 42000 1700 200

105 18900 1690 300

130 21700 2600 300

35
i) Display NAME of all doctors who are in “MEDICINE” having more than 10 years
experience from table DOCTOR

ii) Display the average salary of all doctors working in “ENT” department using the
tables DOCTOR and SALARY. (Salary=BASIC+ALLOWANCE)

iii) Display minimum ALLOWANCE of female doctors.

iv) Display [Link] , NAME from the table DOCTOR and BASIC , ALLOWANCE from
the table SALARY with their corresponding matching ID.

v) To display distinct department from the table doctor.

Output:

i) select NAME from DOCTOR where DEPT=”MEDICINE” and EXPERIENCE >10;


NAME
Bill

ii)select avg(BASIC+ALLOWANCE) “avg salary” from DOCTOR , SALARY where


[Link]=[Link] and DEPT=”ENT”;

Avg salary
13000.00

iii) select min(ALLOWANCE) from SALARY, DOCTOR where SEX=’F’ and


[Link]=[Link];

min(ALLOWANCE)
1700

36
iv) select [Link], NAME, BASIC ,ALLOWANCE from DOCTOR,SALARY where
[Link]=[Link];

ID NAME BASIC ALLOWANCE

101 John 12000 1000

104 Smith 23000 2300

107 George 32000 4000

109 K George 42000 1700

114 Lara 12000 5200

130 Morphy 21700 2600

v) select distinct(DEPT) from DOCTOR;

DEPT

ENT

ORTHOPEDIC

CARDIOLOGY

SKIN

MEDICINE

37
[Link]: 20 Integrate python with sql - fetching records from table
Date: 13-10-2025

Aim: To integrate SQL with Python by importing the MySQL module and extracting data
from result set

Program:

import [Link] as sqltor

mycon=[Link](host=”localhost”, user=”root”, password=”vips”, database=”trinity”)

if mycon.is_connected( ) == False:

print(“Error connecting to MySQL database”)

cursor=[Link]( )

[Link](“select * from student”)

data=[Link](3)

count=[Link]

for row in data:

print(row)

[Link]( )

Output:

(1001, “Vinusha”, 50,70, 80 , “Namakkal”)

(1001, “Aswin”, 54,82, 85 , “Erode”)

(1001, “Bheem”, 90,73, 78 , “Salem”)

Result: Thus the given program executed successfully.


38
[Link]: 21 Integrate python with sql - counting records from table
Date: 23-10-2025

Aim: To integrate SQL with Python by importing the MySQL module and extracting data
from result set

Program:

import [Link] as sqltor

mycon=[Link](host=”localhost”, user=”root”, password=”root”, database=”trinity”)

if mycon.is_connected( ) == False:

print(“Error connecting to MySQL database”)

cursor=[Link]( )

[Link](“select * from student”)

data=[Link]( )

count=[Link]

print(“Total number of rows retrieved from resultset :”, count)

data=[Link]( )

count=[Link]

print(“Total number of rows retrieved from resultset :”, count)

data=[Link](3)

count=[Link]

print(“Total number of rows retrieved from resultset :”, count)

39
Output:

Total number of rows retrieved from resultset : 1

Total number of rows retrieved from resultset : 2

Total number of rows retrieved from resultset : 5

Result: Thus the given program executed successfully.

40
[Link]: 22 Integrate sql with python - searching a record from table
Date: 29-10-2025

Aim: Integrate SQL with Python by importing the MySQL module to search an employee
using eno if it is present in table display the record

Program:

import [Link] as mc
mycon=[Link](host='localhost',user='root',password='root1',database='db12')

if mycon.is_connected( ):

print("Py->Sql connected")

eno=int(input("Enter num:"))

mcursor=[Link]( )

[Link]("select * from emp")

allrow=[Link]( )

for row in allrow:

if row[0]==eno:

print(row)

[Link]( )

Output:

Py-> sql is connected Enter num : 103

(103,’Cinu , 43, ‘Namakkal’)

Result:

Thus the given program executed successfully.

41
[Link]: 23 Integrate sql with python - deleting a record from table
Date: 04-11-2025

Aim: To integrate SQL with Python by importing the MySQL module to search a student
using rollno and delete the record.

Program:

import [Link] as mc
mycon=[Link](host='localhost',user='root',password='root1',database='db12')

if mycon.is_connected():

print("Py->Sql connected")

eno=int(input("Enter num:"))

mcursor=[Link]()

[Link]("select * from emp")

allrow=[Link]()

for row in allrow:

if row[0]==eno:

[Link]("delete from emp where eno={}".format(eno))

[Link]()

[Link]("select * from emp")

print([Link]())

[Link]()

42
Output:

Py -> sql is connected Enter num : 102

(101,’Anu’,23,’Salem’)

(103,’Cinu’,43,’Namakkal’)

(104, ‘Nishanth’, 46,’Chennai’)

(105, ‘Nanda’, 56, ‘Erode’)

Result:

Thus the given is program executed successfully.

43
[Link]: 24 Company and customer
Date: 10-11-2025

Aim: To create two tables for company and customer and execute the given
commands using SQL.

TABLE: COMPANY

TABLE: CUSTOMER

1. To display those company name which are having price less than 30000.
2. To display the name of the companies in reverse alphabetical order.
3. To increase the price by 1000 for those customer whose name starts
with ‘S’

4. To add one more column totalprice with decimal (10,2) to the table
customer

5. To display the details of company where productname as mobile.

44
Output :

1. Select name from company where [Link]=customer. cid and price < 30000

NAME
NEHA SONI
2. Select name from company order by name desc;

NAME

SONY

ONIDA

NOKIA

DELL

BLACKBERRY

3. update customer set price = price + 1000 where name like ‘s%’; select * from customer;

CUSTID NAME PRICE QTY CID

101 ROHAN SHARMA 70000 20 222

102 DEEPAK KUMAR 50000 10 666

103 MOHAN KUMAR 30000 5 111

104 SAHIL BANSAL 36000 3 333

105 NEHA SONI 25000 7 444

106 SONA AGARWAL 21000 5 333

107 ARUN SINGH 50000 15 666

45
4. alter table customer add totalprice decimal(10,2); Select * from customer;

CUSTID NAME PRICE QTY CID TOTALPRICE

101 ROHAN SHARMA 70000 20 222 NULL

102 DEEPAK KUMAR 50000 10 666 NULL

103 MOHAN KUMAR 30000 5 111 NULL

104 SAHIL BANSAL 36000 3 333 NULL

105 NEHA SONI 25000 7 444 NULL

106 SONA AGARWAL 21000 5 333 NULL

107 ARUN SINGH 50000 15 666 NULL

5. select * from company where productname=’mobile’;

CID NAME CITY PRODUCTNAME

222 NOKIA MUMBAI MOBILE

444 SONY MUMBAI MOBILE

555 BLACKBERRY MADRAS MOBILE

46
[Link]: 25 Sql: Teacher (relation)
Date: 18-11-2025

Aim: To create table for teacher and execute the given commands using SQL.

TABLE : TEACHER

No Name Age Department DateofJoin Salary Sex

1 Jishnu 34 Computer 10/01/97 12000 M

2 Sharmila 31 History 24/03/98 20000 F

3 Santhosh 32 Maths 12/12/96 30000 M

4 Shanmathi 35 History 01/07/99 40000 F

5 Ragu 42 Maths 05/09/97 25000 M

6 Shiva 50 History 27/02/97 30000 M

7 Shakthi 44 Computer 25/02/97 21000 M

8 Shriya 33 Maths 31/07/97 20000 F

1. To show all information about the teacher of history department.

2. To list the names of female teacher who are in Maths department.

3. To list names of all teachers with their date of joining in ascending order.

4. To count the number of teachers with age>35.

5. To count the number of teachers department wise.

47
Output:

1. select * from teacher where Department=’History’;

No Name Age Department DateofJoin Salary Sex

2 Sharmila 31 History 24/03/98 20000 F

4 Shanmathi 35 History 01/07/99 40000 F

6 Shiva 50 History 27/02/97 30000 M

2. select Name from teacher where Department=’Maths’ and Sex=’F’;

Name
Shriya

3. select Name , Dateofjoin from teacher order by Dateofjoin asc;

Name Dateofjoin

Santhosh 12/12/96

Jishnu 10/01/97

Shakthi 25/02/97

Shiva 27/02/97

Shriya 31/07/97

Ragu 05/09/97

Sharmila 24/03/98

Shanmathi 01/07/99

48
4. select count(*) from teacher where Age>35;

count(*)

5. select Department , count(*) from teacher group by department;

Department count(*)

Computer 2

History 3

Maths 3

49

You might also like