2ndpuc CS 09042025
2ndpuc CS 09042025
SECOND YEAR P U C
1
List of practical problems - II PU Course
PART – A
Python
1) Write a python program using a function to print n fibonacci numbers.
2) Write a menu driven program in python to find factorial and sum of natural of n Numbers using
function.
3) Write a python program using user defined function to calculate interest amount using simple interest
method and compound interest method and find the difference of interest amount between the two
methods.
4) Write a Python Program to create a text file and to read a text file and display the number of vowels,
consonants, uppercase and lowercase characters in the file.
5) Write a python code to find the number of lines, number of words and number of characters in a text
file.
6) Write a python program to create and to read records in binary file with student name and marks of
six subjects.
7) Write a python program to copy the records of the students having percentage 90 and above from the
binary file into another file.
8) Write a python program using function to sort the elements of a list using bubble sort method.
9) Write a python program using function to sort the elements of a list using selection sort method.
10) Write a python program using function to sort the elements of a list using insertion sort method.
11) Write a python program using function to search an element in a list using linear search method.
12) Write a python program using function to search an element in a list using binary search method.
13) Write a python program to add and display elements from a stack using list.
14) Write a python program to add and display elements from a queue using list.
PART B
MYSQL
B1) Create a table with the following fields and enter 10 records into the table.
Entity Name: marks
2
(i) List all the records
(ii) Display the description of the table
(iii) Add the new attributes total and percent
(iv) Calculate total and percentage of marks for all the students
(v) List the students whose percentage of marks is more than 60%.
(vi) List the students whose percentage is between 60 % and 85%.
(vii) Arrange the students based on percentage of marks from highest to lowest.
B2) Create a table for house hold Electricity bill with the following fields and enter 10 records.
Entity Name: BESCOM
Attributename Type Size Constraint
RRNO Varchar 10 Primary key
CUSTNAME Varchar 25 Not null
BILLDATE DATE
UNITS INT 4
B3) Create a table with the following details and enter 10 records into the table.
3
B4) Create a table with following fields and enter 10 records into the table.
4
PRACTICAL EXAMINATION
Sl. No Program Marks
1 Writing 1 Program from PART-A (Python) 6 Marks
Writing 1 Program from PART-B
2 6 Marks
(SQL)
3 Execution of any one program of examiner’s choice 8 Marks
4 Practical record 6 Marks
Viva-voce (Four Questions related to the program
5 4 Marks
written by the student in Exam)
Total 30 Marks
5
PART A
PYTHON
A1. Write a python program using a function to print fibonacci series up to n numbers
# Fibonacci numbers
def fibo(n):
num1 = 0
num2 = 1
next_number = num2
count = 2
print(num1," ", num2, end=" ")
while count <n:
print(next_number, end=" ")
count += 1
num1, num2 = num2, next_number
next_number = num1 + num2
n = int(input("enter the Limit"))
fibo(n)
print()
OUTPUT:
0 1 1 2 3 5 8 13 21 34 55 89
6
A2. Write a Menu driven program in python to find factorial, and sum of natural Numbers using a
function
# Python program to find factorial of given number and Sum of natural numbers
def fact(n):
return 1 if (n==1 or n==0) else n * fact(n - 1);
def sum(n):
return 0 if (n==0) else n+sum(n-1);
num = int(input("Enter any number : "))
OUTPUT:
7
A3. Write a python program using user defined function to calculate interest amount using simple
interest method and compound interest method and find the difference of interest amount
between the two methods.
OUTPUT:
8
A4. Write a Python Program to read a text file and display the number of
vowels, consonants, uppercase and lowercase characters in the file
# Python Program to create a text file and to read a text file and display the number of
# vowels, consonants, uppercase and lowercase characters in the file
def count_characters(file_name):
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0
uppercase_count = 0
lowercase_count = 0
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
print("Vowels:" , vowel_count)
print("Consonants: ", consonant_count)
print("Uppercase characters: ",uppercase_count)
print("Lowercase characters: ", lowercase_count)
file_name = "sample.txt"
content = input("enter few sentences to create a text file with content: ")
create_text_file(file_name, content)
count_characters(file_name)
OUTPUT:
enter few sentences to create a text file with content: This program is TO Create a FILE
Vowels: 11
Consonants: 15
Uppercase characters: 8
Lowercase characters: 18
9
A5) Write a python code to count the number of lines, number of words and number of characters
in a text file.
file_name = "sample.txt"
content = """Hello Students
This is a sample text file.
It contains multiple lines."""
create_text_file(file_name, content)
count_text_file(file_name)
OUTPUT:
Lines: 3
Words: 12
Characters: 70
10
A6) Write a python program to create and to read records in binary file with student name and
marks of six subjects.
import pickle
while True:
print(''' 1. Create Binary File.
2. Display the File.
3. Exit''')
a=int(input('choose a command (1-2,3-exit): '))
if a==1:
f=open('student.dat','wb')
x=int(input('How many student: '))
for i in range(x):
name=input('Name: ')
english=int(input('English Mark: '))
lan=int(input("Language Marks"))
phy=int(input('Physics Mark: '))
chem=int(input('Chemistry Mark: '))
maths=int(input('Maths Mark: '))
cs=int(input('CS Mark: '))
t=[name,english,lan,phy,chem,maths,cs]
pickle.dump(t,f)
f.close()
elif a==2:
f=open('student.dat','rb')
try:
while True:
p=pickle.load(f)
print(p)
except:
f.close()
if a>2:
break
OUTPUT:
1. Create Binary File.
2. Display the File.
3. Exit
choose a command (1-2, 3-exit): 2
['Bharath', 77, 88, 99, 77, 88, 99]
['Guru', 77, 88, 99, 77, 88, 99]
['Manjula', 88, 99, 88, 99, 88, 88]
['Rekha', 99, 88, 99, 99, 88, 88]
['Uday', 66, 77, 66, 77, 66, 77]
1. Create Binary File.
2. Display the File.
3. Exit
choose a command (1-2,9-exit):3
11
A7. Write a python program to copy the records of the students having percentage 90 and above
from the binary file into another file.
# program to create and copy records to copy records with percentage 90 and above into another file.
import pickle
while True:
print(''' 1. Create Binary File.
2. Display the main File.
3. Create new file wirh >90
4. Exit''')
a=int(input('choose a command (1-2,9-exit): '))
if a==1:
f=open('student.dat','wb')
o=open('stuii.dat','wb')
x=int(input('How many student: '))
for i in range(x):
name=input('Name: ')
english=int(input('English Mark: '))
lan=int(input("Language Marks"))
phy=int(input('Physics Mark: '))
chem=int(input('Chemistry Mark: '))
maths=int(input('Maths Mark: '))
cs=int(input('CS Mark: '))
total=phy+chem+cs+maths+english+lan
per=(total / 600) * 100
t=[name,english,lan,phy,chem,maths,cs,total,per]
g=[name,english,lan,phy,chem,maths,cs,total,per]
pickle.dump(t,f)
if per>=90:
pickle.dump(g,o)
f.close()
o.close()
elif a==2:
f=open('student.dat','rb')
try:
while True:
p=pickle.load(f)
print(p)
except:
f.close()
elif a==3:
print("Studets with > 90 Marks")
f=open('stuii.dat','rb')
try:
while True:
o=pickle.load(f)
print(o)
except:
f.close()
12
else:
break
OUTPUT:
13
A8. Write a python program using function to sort the elements of a list using bubble sort method
# program using function to sort the elements of list using bubble sort method
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
def input_list():
arr = []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
element = int(input("Enter element "))
arr.append(element)
return arr
arr = input_list()
print("Original list:", arr)
bubble_sort(arr)
print("Sorted list:", arr)
OUTPUT:
14
A9. Write a python program using function to sort the elements of a list using selection sort
method
def input_list():
arr = []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
element = int(input("Enter element "))
arr.append(element)
return arr
arr = input_list()
selection_sort(arr)
print("Sorted list:", arr)
OUTPUT:
15
A10. Write a python program using function to sort the elements of a list using insertion sort
method
# python program using function to sort the elements of list using insertion sort method
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j=i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
def input_list():
arr = []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
element = int(input("Enter element "))
arr.append(element)
return arr
arr = input_list()
print("Original list:", arr)
insertion_sort(arr)
print("Sorted list using insertion sort method:", arr)
OUTPUT:
16
A11. Write a python program using function to search an element in a list using linear search
method
arr = input_list()
target = int(input("Enter the element to search for: "))
OUTPUT:
17
A12. Write a python program using function to search an element in a list using binary search
method.
def input_list():
arr = []
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
element = int(input("Enter the elements in ascending order "))
arr.append(element)
return arr
arr = input_list()
target = int(input("Enter the element to search for: "))
OUTPUT:
18
A13. Write a python program to add and display elements from a stack using list
stack.append('x')
stack.append('y')
stack.append('z')
print(stack)
OUTPUT:
19
A14. Write a python program to add and display elements from a queue using list
# python program to add and display elements from a queue using list
# Create Queue and perform insert and delete
import queue
OUTPUT:
20
PART B
MYSQL
B1) Create a table with the following fields and enter 10 records into the table.
Entity Name: marks
INSERT INTO marks VALUES(1010, 'RAJ', 89, 97, 98, 99, 86, 95)
INSERT INTO marks VALUES (1026, 'KIRAN', 67, 62, 72, 86, 72, 62)
INSERT INTO marks VALUES (1042, 'ANAND', 78, 87, 92, 82, 72, 76)
INSERT INTO marks VALUES (1250, 'RAM', 72, 86, 72, 62, 87, 68)
INSERT INTO marks VALUES (5212, 'VIJAYA', 46, 58, 86, 92, 72, 62)
INSERT INTO marks VALUES (3622, 'MANOJ', 86, 56, 62, 86, 52, 64)
INSERT INTO marks VALUES (1948, 'REEHAN', 63, 68, 52, 56, 96, 76)
INSERT INTO marks VALUES (1482, 'KAJOL', 49, 54, 48, 76, 62, 55)
INSERT INTO marks VALUES (1947, 'KUMAR', 98, 98, 99, 100, 97, 99)
21
(i) List all the records
select * from marks;
(ii) Display the description of the table
describe marks;
(iii) Add the new attributes total and percent
alter table marks add(total int(3), percent float(5,3));
(iv) Calculate total and percentage of marks for all the students
update marks set total = lang_mks+eng_mks+sub1_mks+sub2_mks+sub3_mks+sub4_mks;
(v) List the students whose percentage of marks is more than 60%.
select sname, percent from marks where percent >=60;
(vi) List the students whose percentage is between 60% and 85%.
select sname, percent from marks where percent between 60 and 85;
(vii) Arrange the students based on percentage of marks from highest to lowest.
select sname, percent from marks order by percent desc;
22
B2) Create a table for house hold Electricity bill with the following fields and enter 10 records.
Entity Name: BESCOM
Attributename Type Size Constraint
RRNO Varchar 10 Primary key
CUSTNAME Varchar 25 Not null
BILLDATE DATE
UNITS INT 4
10. Compute the bill amount for each consumer as per the following rules.
a. MINIMUM Amount Rs. 100
b. For first 100 units Rs 7.50/Unit
c. For the above 100 units Rs. 8.50/Unit
(i) UPDATE BESCOM SET BILLAMT = 100 + UNITS * 7.50 WHERE UNITS <= 100;
23
(ii) UPDATE BESCOM SET BILLAMT = 100 + (100 * 7.50) + (UNITS - 100) * 8.50 WHERE
UNITS > 100;
12. List all the bills generated in a sorted order based on RRNO.
select rrno from bescom order by rrno;
24
B3) Create a table with the following details and enter 10 records into the table.
(vi) List the students who born in the month of June of any year.
SELECT * FROM student WHERE MONTH(dob) = 6;
25
B4) Create a table with following fields and enter 10 records into the table.
INSERT INTO Library VALUES('The Data Science Handbook', 'Darshan', 2019, 'Data science',
750.00, 12)
INSERT INTO Library VALUES ('Introduction to Computer Programs', 'Harshavardhan',
NULL, 'Computer Science', 700.00, 6)
INSERT INTO Library VALUES ('Computer Science Text book Class 12', 'Reeta Sahoo', 2019,
'Textbook', 450.00, 4)
INSERT INTO Library VALUES ('A book on AI', 'Sagar', 2016, 'AI', 200.00, 7)
INSERT INTO Library VALUES ('Robots and Automation', 'Dushyanth', 2018, 'Digital
Technology', 750.00, 9)
INSERT INTO Library VALUES ('AI 2041', 'Chen & Lee', 2021, 'AI', 1000.00, 2)
INSERT INTO Library VALUES ('Computer Hardware and Software', 'Chethan', 2000,
'Computer science', 500.00, 7)
INSERT INTO Library VALUES ('The Future of Work', 'Dev Kumar', 2018, 'Digital
Technology', 750.00, 4)
INSERT INTO Library VALUES ('Healthcare and AI', 'Eshwar', 2019, 'AI', 950.00, 9)
INSERT INTO Library VALUES ('Introduction to Data Science', 'Dravid', 2014, 'Data Science',
400.00, 5);
(iii) List the records of all those books price is between 400 and 900.
select price from library where price between 400 and 900;
(v) List the names of the authors whose name starts with letter ‘C’ or ‘D’.
select Author from library where author like 'C%' or author like 'D%';
(vi) List Title, year and category from the table library with category field has word ‘science’.
SELECT Title, Year, Category FROM Library WHERE Category LIKE '%science%';
(vii) List all those records whose year of publication is 2010 onwards with book price is less than
Rs.750.
SELECT year, price FROM Library WHERE Year >= 2010 AND Price < 750;
-oOo-
27