We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
KENDRIYA VIDYALAYA
NO. 2 AGRA CANTT
(SESSION 2023-24)
C.B.S.E PRACTICAL EXAMINATION
SUBMITTED TO:
MR MITRA BHUSHAN SIR (PGTCS)
SUBMITTED BY:
DEV SINGH (XiI-A)
‘SIGNATURE EXAMINER: SIGNATURE TEACHER'S.NO
INDEX
EA
WAP to show functionality of a basic
calculator using functions.
Write a function in python which
accept a number from user to return
True, if the number is a prime number
else return False. Use this function to
print all prime numbers from 1 to 100.
Write a function in python which
accepta list of marks of students and
return the minimum mark, maximum
mark and the average marks, Use the
same function to test.
WAP to read a text file “myfile.txt’ line
by line and display each word
separated by a #.
WAP to read a text file “myfile.txt” and
display the number of vowels/
consonants/ uppercase/ lowercase
characters in the file.
Remove all the lines that contain the
character ‘a’ ina file and write it to
another file.
Write a program to create a text file
and print the lines starting with ‘T”
or‘P’. (Both uppercase and
lowercase).
PAGE NO.
1
RI [¢iRead a text file to print the frequency of the
word ‘He’ and ‘She’ found in the file.
Create a binary file with name and roll number.
Search for a given roll number and display the
name, if not found display appropriate
message.
Create a binary file with roll number, name and
marks. Input a roll number and update the
marks.
Read a CSV file from hard disc and print all the
details on the screen.
Read a CSV file (containing item no, name, rate,
QOH) from hard disc and printall the items
whose rate is between Rs 500 and Rs 1000.
Create a CSV file by entering user-id and
password, read and search the password for
given user id.
Write a random number generator that
generates random numbers between 1 and 6
(simulates a dice). Throw the two dices for 10
times and print their total.
WAP in Python to demonstrate linear search.
Write a Python program to implement a stack
using alist data-structure.
10
11
12
13
14
15
16ary
a
WAP to pass an integer list as stack toa
function and push only those elements in the
stack which are divisible by 7.
Queries using Create database Show databases,
Use Create table, Show Tables, Describe,
Rename, Alter, Select, From, Where, Insert,
Update commands
Queries using DISTINCT, BETWEEN, IN, LIKE,
IS NULL, ORDER BY, GROUP BY, HAVING
Queries for Aggregate functions- SUM(), AVG(
), MIN(), MAX(), COUNT()
WAP to connect Python with MySQL using
database connectivity and perform the following
operation on data in database: Create a table in
database
WAP to connect Python with MySQL using
database connectivity and perform the
following operation on data in database: Insert
record in the table
WAP to connect Python with MySQL using
database connectivity and perform the following
operation on data in database: Fetch records
from the table using fetchone( ), fetchall() and
fetchmany( ).
WAP to connect Python with MySQL using
database connectivity and perform the
following operation on data in database:
Update record in the table
‘WAP to connect Python with MySQL using
database connectivity and perform the
following operation on data in database: Delete
record from the table
17
18
19
20
21
22,
23)
24
231). WAP to show functionality of a basic calculator using
functions.2). Write a function in python which accept a number from user to
return True, if the number is a prime number else return False. Use
this function to print all prime numbers from 1 to 100.
(numb
if number < 2:
westeot aly) or 1)
return Fal
urn True
num in range(1, 101):
samba pel3. Write a function in python which accept a list of marks of
students and return the minimum mark, maximum mark and the
average marks. Use the same function to test.
m
(£"Minimum4. WAP to read a text file “myfile.txt” line by line and display each
word separated by a #.5. WAP to read a text file “myfile.txt” and display the number of
vowels/ consonants/ uppercase/ lowercase characters in the file.6. Remove all the lines that contain the character ‘a’ ina file and
write it to another file.
ut_file, output_fil7. Write a program to create a text file and print the lines starting
with ‘T’ or ‘P’. (Both uppercase and lowercase).8. Read a text file to print the frequency of the word ‘He’ and ‘She’
found in the file.9. Create a binary file with name and roll number. Search for a
given roll number and display the name, if not found display
appropriate message10. Create a binary file with roll number, name and marks. Input a
roll number and update the marks.11. Read a CSV file from hard disc and print all the details on the
screen.
esa
Pd12. Read a CSV file (containing item no, name, rate, QOH) from
hard disc and print all the items whose rate is between Rs 500
and Rs 1000.13. Create a CSV file by entering user-id and password, read and
search the password for given user id.
Peeroeee]14. Write a random number generator that generates random
numbers between 1 and 6 (simulates a dice). Throw the two dices for
10 times and print their total.15. WAP in Python to demonstrate linear search.16. Write a Python program to implement a stack using a list data-
structure.
eee eet sete
neraeere17. WAP to pass an integer list as stack to a function and push
only those elements in the stack which are divisible by 7.
(Cie
SME RoE BE1. Queries using Create database, Show databases, Use, Create table, Show Tables, Describe,
Rename, Alter, Select, From, Where, Insert, Update commands
~ Create a Database
CREATE DATABASE your_database;
-- Show Databases
SHOW DATABASES;
-- Use a Database
USE your_databases
-- Create a Table
CREATE TABLE your_table (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
)
-- Show Tables
SHOW TABLES;
-- Describe a Table
DESCRIBE your_table;
-- Rename a Table
RENAME TABLE old_table TO new_table;
-- Alter Table (Add a Column)
ALTER TABLE your_table ADD COLUMN new_column INT;
-- Select Data from a Table
SELECT * FROM your_table;
-- Select Data with a Condition
SELECT * FROM your_table WHERE age > 18;
~ Insert Data into a Table
INSERT INTO your_table (id, name, age) VALUES (1, ‘John Doe’, 25);
~- Update Data in a Table
UPDATE your_table SET age = 26 WHERE id = 1;2. Queries using DISTINCT, BETWEEN, IN, LIKE, IS NULL, ORDER BY, GROUP BY, HAVING
-- Create a Database
CREATE DATABASE your_database;
-- Show Databases
SHOW DATABASES;
-- Use a Database
USE your_database;
-- Create a Table
CREATE TABLE your_table (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
)s
-- Show Tables
SHOW TABLES;
-- Describe a Table
DESCRIBE your_table;
~ Rename a Table
RENAME TABLE old_table TO new_table;
-- Alter Table (Add a Column)
ALTER TABLE your_table ADD COLUMN new_column INT;
~- Select Data from a Table
SELECT * FROM your_table;
-- Select Data with a Condition
SELECT * FROM your_table WHERE age > 18;
~- Insert Data into a Table
INSERT INTO your_table (id, name, age) VALUES (1, "John
Doe’, 25);
~ Update Data in a Table
UPDATE your_table SET age = 26 WHERE i3. Queries for Aggregate functions- SUM(), AVG( ), MIN( ), MAX( ), COUNT( )
cc) =i ea
SUM(column_name) AS total_sum,
AVG(column_name) AS average_value,
MIN(column_name) AS min_value,
MAX(column_name) AS max_value,
COUNT(*) AS row_count
FROM your_table;4 WAP to connect Python with MySQL using database connectivity and perform
the following operation on data in database: Create a table in database
import mysql.connector
def create_table():
# Connect tothe MySQL server
connection =
mysql.connector.connect(host="your_host",user="your_user",password="your_password’ database="your_database" )
# Create a cursor object to interact with the database
cursor = connection.cursor()
#Createatable
create_table_query ="""CREATE TABLE your_table(id INT PRIMARY KEY, name VARCHAR(255), age INT)"
Cursor.execute(create_table_query)
# Commit the changes
connection.commit()
# Close the cursor and connection
cursor.close()
connection.close()
# Call the create_table function to perform the table creation
create_table()SWAP to connect Python with MySQL using database connectivity and perform the following
operation on data in database: Insert record in the table
import mysql.connector
def insert_record():
# Connect to the MySQL server
connection =
=" your_user" passwords" your_password” database=" your_database)
mysql.connector.connect(host="you
act with the database
# Create object to im
cursor = connection.cursor()
# Insert a record into the table
insert_query = "INSERT INTO your_table (column1, column2, column3) VALUES (%s, %s, 9%)
values = (valuel, value2, value3) # Replace with actual values
cursor.execute(insert_query, values)
# Commit the changes
connection.commit()
# Close the cursor and connection
cursor.close()
connection.close()
# Call the insert_record function to perform the insert
insert_record()6. WAP to connect Python with MySQL using database connectivity and perform
the following operation on data in database: Fetch records from the table using
fetchone( ), fetchall() and fetchmany( ).
import mysql.connector
# Connect to the MySQL server
connection = mysql.connector.connect(
host="your_host",
user="your_user",
password="
database="your_database")
our_password",
# Create a cursor object to interact with the database
cursor = connection.cursor()
# Fetch records using fetchone()
cursor.execute("SELECT * FROM your_table")
one_record = cursor.fetchone()
print("Fetch One:", one_record)
# Fetch all records using fetchall()
cursor.execute("SELECT * FROM your_table")
all_records = cursor. fetchall()
print("Fetch All:", all_records)
# Fetch a specific number of records using fetchmany()
cursor.execute("SELECT * FROM your_table")
some_records = cursor.fetchmany(size=3) # Adjust the size as needed
print("Fetch Many:", some_records)
# Close the cursor and connection
cursor.close()
connection.close()7. WAP to connect Python with MySQL using database connectivity and perform
the following operation on data in database: Update record in the table
import mysql.connector
def update_record():
# Connect to the MySQL server
connection = mysql.connector.connect(
host="your_host"user="your_user” password="your_password" database=" your database")
# Create a cursor object to interact with the database
cursor = connection.cursor()
# Update a record in the table
update_query = "UPDATE your_table SET column_to_update
condition_column = %s"
new_value = "new_value” # Replace with the new value you want to set
condition_value = "condition_value" # Replace with the condition value
%s WHERE
cursor.execute(update_query, (new_value, condition_value))
#Comn
connection.commit()
tthe changes
# Close the cursor and connection
cursor.close()
connection.close()
# Calll the update_record function to perform the update
update_record()8. WAP to connect Python with MySQL using database connectivity and perform
the following operation on data in database: Delete record from the table
import mysql.connector
def delete_record():
# Connect to the MyS
QL server
connection = mysql.connector.connect(
ho:
your_host" use your_database")
your_user” password:
your_password” databas
# Create a cursor object to interact with the database
cursor = connection.cursor()
# Delete a record from the table
delete_query DELETE FROM your_table WHERE condition_column = %s"
condition_ “condition_value” # Replace with the condition value
carsorexecute(delete_query, (condition_valuc,))
# Commit the changes
connection.commit()
# Close the cursor and connection
cursor.close()
connection.close()
# Call the delete_record function to perform the delete
delete_record()