Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views12 pages

Class 12 Practical Questions 2024-25

The document outlines practical assignments for Class XII Computer Science, covering various programming tasks in Python, file handling, binary file operations, and SQL commands. It includes exercises on data structures like stacks and queues, as well as operations on CSV files for managing student records. Each assignment consists of multiple programming challenges aimed at enhancing students' coding skills and understanding of computer science concepts.

Uploaded by

vr418273
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)
26 views12 pages

Class 12 Practical Questions 2024-25

The document outlines practical assignments for Class XII Computer Science, covering various programming tasks in Python, file handling, binary file operations, and SQL commands. It includes exercises on data structures like stacks and queues, as well as operations on CSV files for managing student records. Each assignment consists of multiple programming challenges aimed at enhancing students' coding skills and understanding of computer science concepts.

Uploaded by

vr418273
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
You are on page 1/ 12

Class XII Computer Science (083)

Practical Assignment #1

1. Write a Python program to do the following:


a. Create a list of N numbers
b. Input the position of the element to be deleted from the list and delete the element at
the desired position in the list.
c. Input the element and the position where it is to be inserted in the list.
d. Display the list

2. Write a program to read a list of n integers (positive as well as negative). Create two new
lists, one having all positive numbers and the other having all negative numbers from the
given list. Print all the three lists.

3. Write a program in Python to enter the list of N numbers and do the following:
a. Display the list.
b. Display the largest and smallest number in the list.
c. Display the third largest number in the list.
d. Input another list of five numbers and add it with the original list. Display the list.

4. Write a program to read a list of N numbers and display the list in reverse order without
using any function.

5. Write a program to read a list of N numbers and replace odd position element with even
position element. Display the final list.

6. Write a program to read a list of N numbers and replace the even values with number
divided by 2 and odd values with number multiply with 5. Display the final list.

7. Write a program to input your friend’s names and their phone numbers and store them in
the dictionary as the key-value pair. Perform the following operations on the dictionary:
a. Display the name and phone number for all your friends.
b. Enter the name whose phone number you want to modify. Display the modified
dictionary.

8. Write a program to input roll number and marks obtained in five subjects of N number of
students. Store the data in a dictionary as the key-value pair. Perform the following
operations on the dictionary:
a. Display the roll number and marks obtained in five subjects.
b. Calculate the sum of five subjects and display the roll number and sum of all the five
subjects.

9. Write a program to count the number of times a character appears in a given string.

10. Write a program to convert a number entered by the user into its corresponding number in
words. For example, if the number is 876, then the output should be ‘Eight Seven Six’

11. Write a program in Python to input a number and display whether it is a prime number or
not.

12. Write a program in Python to input a string and display whether it is a palindrome or not.
13. Write a program in python to input two numbers and display the greatest common
divisor.

14. Write a program in Python to input two numbers and display the least common multiple.

15. Write a program in Python to input a number and display whether it is an Armstrong
number or not. An Armstrong number is where number is equal to the sum of cube of
the digits.
16. Write a program in Python that input a number - how many times random number is
generated, and generates random numbers between 1 and 6.

Class XII Computer Science (083)


Practical Assignment #2

1. Write a program in Python using function factorial(n) to calculate and return the
factorial of number n passed to the parameter.

2. Write a program in Python with function sumdigits(n) to calculate and return


the sum of digits of number n passed to the parameter.

3. Write a program in Python with function reverse(n) to calculate and return the
reverse of a number n passed to the parameter.

4. Write a program in Python with function sum(L) to calculate and return the
sum of all the elements in a list.

5. Write a program in Python with function fibo(n) to computer the nth Fibonacci
number.

6. Write a program in Python with function plaindrome(str) to display whether it is


palindrome or not.

7. Write a program in Python with function recgcdf(a, b) to display the greatest


common divisor

8. Write a program in Python with function reclcm(a,b) to display the lowest


common multiple.

9. Write a program in Python with function isprime(n) to display whether it isa prime
number or not.

10. Write a program in Python with function recseries(N) to display the sum ofthe
series S = 12 + 22 + 32 + ................. N2
Class XII Computer Science (083)
Practical Assignment #3 (Text File)

1. Write a program in Python to read a file line by line and print it on the screen.
2. Write a program in Python to remove all the lines that contain the character ‘a’ in a
file and write it to another file.
3. Write a function in python to count the number of lines in a text file ‘Story.txt’ which
is starting with an alphabet ‘A’.
4. Write a function DISPLAYWORDS() in Python to read lines from a text file
‘Story.txt’ and display those words, which are less than 4 characters.
5. Write a function in Python to read a text file line by line and display each word
separated by #.
6. Write a function in Python to read a text file and display the number of
vowels/consonants/uppercase / lowercase characters in a file.
7. Write a program in python to read a text file (any phishing email) and find out most
commonly occurring word(s).

Class XII Computer Science (083) 2020-21


Practical Assignment #4 (Binary File)

1. Create a binary file with name and roll number. Search for a given roll number and
display the name, if not found display an appropriate message.
2. Create a binary file with roll number, name and marks. Input the roll number and
update the marks
3. Following is the structure of each record in a data file named “product.dat”
{"prod_code":value, "prod_desc":value, "stock":value}
The values for prod_code and prod_desc are strings, and the value for stock is an
integer.
Write a function in PYTHON to update the file with a new value of stock. The stock
and the product_code, whose stock is to be updated, are to be input during the
execution of the function.
4. Given a binary file “STUDENT.DAT”, containing records of the following type:
[S_Admno, S_Name, Percentage] where S_Admno is the admission number of
student(string), S_Name is the name of the student (string) and Percentage is the
marks percentage of student (float).
Write a function in PYTHON that would read contents of the file “STUDENT.DAT”
and display the details of those students whose percentage is above 75.
5. Assuming the tuple Vehicle as follows:
( vehicletype, no_of_wheels) where vehicle type is a string and no_of_wheels is an
integer.
Write a function showfile() to read all the records present in an already existing binary
file SPEED.DAT and display them on the screen, also count the number of records
present in the file.
6. Write a function in PYTHON to search for a BookNo from a binary file
“BOOK.DAT”, assuming the binary file is containing the records of the following type:
{"BookNo":value, "Book_name":value} The BookNo is an integer.

7. Assuming that a binary file VINTAGE.DAT contains records of the following type,
write a function in PYTHON to read the data VINTAGE.DAT and display those
vintage vehicles, which are priced between 200000 and 250000.
[VNO, VDesc, price]

8. Write a function in Python to search for a laptop from a binary file “laptop.dat”
containing records of following type
[ModelNo, RAM, HDD, Details]
Where ModelNo, RAM, HDD are integers and Details is a string.
The user should enter the model number and the function should display the details
of the laptop.

9. Write a function in Python to search for the details of those mobile phones which
have more than 1000 calls from a binary file “mobile.dat”. Assume that binary file
contains records of the following type: (Number, Calls)

10. Write a function in Python to read each record of a binary file “items.dat”, find and
display those items which costs less than 2500. Assume that the file is created with
the help of objects of the following type:
{"ID":string, "GIFT":string, "Cost":integer}

11. Write a function bumper() in Python to read each object of a binary file “gifts.dat”,
find and display details of those gifts, which have remarks as “on discount”. Assume
the file is created with the help of lists of following type:
[ID, Gift, Remarks, Price]
12. Write a Python program to write data into a CSV file named employees.csv. The file should
have columns EmpID, Name, Designation, and Salary.
13. Write a Python program to update the salary of an employee in employees.csv based on their
EmpID.
14. Menu Driven Program:

A school maintains the academic records of students in a CSV file named student_records.csv. The file
contains the following columns:

• StudentID (unique identifier for each student)


• Name
• Class
• Section
• Maths
• Science
• English
• TotalMarks (sum of marks in Maths, Science, and English)

The school administration wants to automate some tasks using Python. You are required to solve the
following problems:

Questions:
1. Data Reading and Displaying

• Question: Write a Python function display_records() that reads the student_records.csv file and
displays all student records in a tabular format.
2. Adding a New Record

• Question: Write a Python function add_student() that takes student details as input (except
TotalMarks) and adds a new record to the student_records.csv file. Ensure that the TotalMarks
field is calculated and added automatically.

3. Updating Marks

• Question: Write a Python function update_marks(student_id, subject, new_marks) that updates


the marks of a specific student in a specific subject. Recalculate the TotalMarks for that student
after updating the marks.

4. Ranking Students

• Question: Write a Python function rank_students() that reads the student_records.csv file and
displays the top 3 students based on TotalMarks.

5. Searching for a Student

• Question : Write a Python function search_student(student_id) that searches for a student by


their StudentID and displays their details.

Class XII Computer Science (083)


Practical Assignment #5 (Stack)

1. Write a program in python to implement queue with the following functions:


● INSERTQ(Arr, data) for insertion operation
● DELETEQ(Arr) for deletion operation
● Exit
Arr is the list used for implementing queue and data is the value to be inserted.

2. Write a function in python to implement stack with the following functions:


● MakePush(Package) for push operation
● MakePop(Package) for pop operation
● Exit
A Package is the list of package description.

3. Write a program in Python to implement a stack of book details – book no, book
name and do the following:
● Add the book details
● Delete the book details
● Display all the records
● Exit

4. Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all
numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at
least one element, otherwise display appropriate error message

5. Vedika has created a dictionary containing names and marks as key-value pairs of 5 students.
Write a program, with separate user-defined functions to perform the following operations:

Push the keys (name of the student) of the dictionary into a stack, where the corresponding
value (marks) is greater than 70.

Pop and display the content of the stack.

Class XII Computer Science (083)


Practical Assignment #6 (SQL Commands)

1. Consider a database LOANS with the following table:


Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R. K. Gupta 300000 36 12.00 19-07-2009
2 S. P. Sharma 500000 48 10.00 22-03-2008
3 K. P. Jain 300000 36 NULL 08-03-2007
4 M. P. Yadav 800000 60 10.00 06-12-2008
5 S. P. Sinha 200000 36 12.50 03-01-2010
6 P. Sharma 700000 60 12.50 05-06-2008
7 K. S. Dhall 500000 48 NULL 05-03-2008

Write SQL commands for the tasks 1 to 35


Create Database and use it
1. Create the database LOANS.
2. Use the database LOANS.

Create Table / Insert Into


3. Create the table Loan_Accounts and insert tuples in it.

Simple Select
4. Display the details of all the loans.
5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.

Conditional Select using Where Clause


6. Display the details of all the loans with less than 40 instalments.
7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.
8. Display the Int_Rate of all the loans started after 01-04-2009.

Using NULL
9. Display the details of all the loans whose rate of interest is NULL.
10. Display the details of all the loans whose rate of interest is not NULL.

Using DISTINCT Clause


11. Display the amounts of various loans from the table Loan_Accounts. A loan amount
should appear only once.
12. Display the number of instalments of various loans from the table Loan_Accounts. An
instalment should appear only once.

Using Logical Operators (NOT, AND, OR)


13. Display the details of all the loans started after 31-12-2008 for which the number of
instalments are more than 36.
14. Display the Cust_Name and Loan_Amount for all the loans which do not have number of
instalments 36.
15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount is
less than 500000 or int_rate is more than 12.
16. Display the details of all the loans which started in the year 2009.
17. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000.
18. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of
instalments are 24, 36, or 48. (Using IN operator)

Using BETWEEN Operator


20. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000. (Using BETWEEN operator)
21. Display the details of all the loans whose rate of interest is in the range 11% to 12%.
(Using BETWEEN operator)

Using LIKE Operator


22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'Sharma'.
23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'a'.
24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a'
25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name does not contain 'P'.
26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a' as the second last character.

Using ORDER BY clause


27. Display the details of all the loans in the ascending order of their Loan_Amount.
28. Display the details of all the loans in the descending order of their Start_Date.
29. Display the details of all the loans in the ascending order of their Loan_Amount and
within Loan_Amount in the descending order of their Start_Date.

Using UPDATE, DELETE, ALTER TABLE


30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than
400000.
32. For each loan replace Interest with (Loan_Amount*Int_Rate*Instalments) 12*100.
33. Delete the records of all the loans whose start date is before 2007.
34. Delete the records of all the loans of 'K.P. Jain'
35. Add another column Category of type CHAR(1) in the Loan table.
EMPNO ENAME JOB HIREDATE SAL COMM DEPTNO
8369 SMITH CLERK 1990-12-18 8000 NULL 20
8499 ANYA SALESMAN 1991-02-20 16000 500 30
8521 MAHADEVAN SALESMAN 1991-02-22 10000 300 30
8566 MOMIN MANAGER 1991-04-02 25000 NULL 10
8654 BINA ANALYST 1992-12-09 30000 NULL 20
8698 SHIAVNSH PRESIDENT 1991-11-18 50000 NULL 10
8882 SCOTT SALESMAN 1991-05-01 12000 1200 30

2. Create the table WORKER and add records as shown below. Write SQL commands
for the statements (a) to (g).
a. To display the details in ascending order of salary.
b. To display empno, empname in descending order of hiredate.
c. To display the details in ascending order of empno.
d. To display the sum of salary with heading ‘Sum of salary’.
e. To display the number of employees in each department number.
f. To display the number of employees in each department but number of employees
should be less than 3.
g. To display the sum of salary, average of salary, maximum and minimum salary of
each job title.

3. Create a table EMPLOYEE with the following data. Write SQL commands for the
statements (a) to (h).
Table: EMPLOYEE

No Name Salary Area Age Grad Dept


e
711 KESHAR 40000 WEST 45 C CIVIL
262 KIRTI 35000 SOUTH 38 A ELEC
693 KRIPPLE 60000 NORTH 52 B CIVIL
724 ARYAN 38000 NORTH 29 B CIVIL
705 SAMSON 42000 EAST 35 A COMP
606 BISWAL 29000 SOUTH 34 A MECH

a. To display the list of all employees in ascending order of salary.


b. To display the employee names in descending order of age.
c. To display the grade and number of employees in each grade.
d. To display the area and number of employees in each area.
e. To display the sum and average salary of the employees of grade ‘B’.
f. To display grade and maximum, minimum and average salary of each grade.
g. To display the sum, average, maximum and minimum of salary.
h. To display grade and the number of employees in each grade where the number of
employees are more than two.
4.Consider the tables HANDSETS and CUSTOMER given below:
Handsets Customer
SetCode SetName TouchScreen Phone Cost
CustNo SetNo CustAddress
N1 Nokia 2G N 5000
1 N2 Delhi
N2 Nokia 3G Y 8000
B1 BlackBerry 2G N 14000 2 B1 Mumbai
3 N2 Mumbai
4 N1 Kolkata
5 B1 Delhi
With reference to these tables, Write commands in SQL for (a) and (b) and output for (c)
below:
a. Display the CustNo, CustAddress and corresponding SetName for each customer.
b. Display the Customer Details for each customer who uses a Nokia handset.
c. select SetNo, SetName from Handsets, customer
where SetNo = SetCode and CustAddress = 'Delhi';

5. Create the following tables SENDER and RECIPIENT. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: SENDER

SenderID SenderName SenderAddress SenderCity


ND01 R Jain 2, ABC Appts New Delhi
MU02 H Sinha 12, Newtown Mumbai
MU15 S Jha 27/A, Park Street New Delhi
ND50 T Prasad 122 K, SDA Mumbai
Table: RECIPIENT

RecID SenderID RecName RecAddress RecCity


K005 ND01 R Bajpayee 5, Central Avenue Kolkata
ND08 MU02 S mahajan 116, A Vihar New Delhi
MU19 ND01 H Singh 2A, Andheri East Mumbai
MU32 MU15 P K Swamy B5, C S Terminus Mumbai
ND48 ND50 S Tripathi 13, Mayur Vihar New Delhi
a. Display the names of all senders from MUMBAI.
b. Display the RecID, SenderName, SenderAddress, RecName, RecAddress for every
recipient.
c. Display the recipient details in ascending order of RecName.
d. Display the number of recipients in each city.
e. SELECT DISTINCT SenderCity FROM sender;
f. SELECT A.SenderName, B.RecName FROM Sender A, Recipient B
WHERE A.SenderID = B. SenderID AND B.RecCity = ‘Mumbai’;
g. SELECT RecName, RecAddress FROM Recipient
WHERE RecCity NOT IN (‘Mumbai’,’Kolkata’);
h. SELECT RecID, RecName FROM Recipient
WHERE SenderID = ‘MU02’ OR SenderID = ‘ND50’;

6. Write the following tables PRODUCT and CLIENT. Write SQL commands for the
statements (a) to (d) and give outputs for SQL queries (e) to (h)
Table: PRODUCT Table: CLIENT
P_ID ProductName Manufacturer Price
C_ID ClientName City P_ID
TP01 Talcom Powder LAK 40
1 Cosmetic Shop Delhi FW05
FW05 Face Wash ABC 45
6 Total Health Mumbai BS01
BS01 Batth Soap ABC 55
12 Live Life Delhi SH06
SH06 Shampoo XYZ 120
15 Pretty One Delhi FW12
FW12 Face Wash XYZ 95
16 Dreams Bangalore TP01

a. To display the details of those clients whose city is Delhi.


b. To display the details of the products whose price is in the range 50 to 100 (Both
values included).
c. To display the ClientName, City from table Client, and ProductName and Price from
table Product, with their corresponding matching P_ID.
d. To increase the price of all products by 10.
e. SELECT DISTINCT City FROM Client;
f. SELECT Manufacturer , MAX(price) , MIN(Price), COUNT(*)FROM Product
GROUP BY Manufacturer;
g. SELECT ClientName , Manufacturer FROM Product P, Client C
WHERE C.P_ID = P.P_ID;
h. SELECT ProductName, Price * 4 FROM Product;
WHERE P_ID = ‘TP01’ OR P_ID = ‘SH06’;

7. Create the following tables WORKER and PAYLEVEL. Write SQL commands for the
statements (a) to (d) and give outputs for SQL queries (e) to (h)
Table: WORKER

ECOD NAM DESIG PLEVE DO DO


E E L J B
11 Radhe Shyam Supervisor P001 13-Sep-2004 23-Aug-1981
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-Jun-2009 14-Oct-1983
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
18 Sanya Clerk P002 19-Dec-2005 09-Jun-1983
Table: PAYLEVEL
PLEVE PAY ALLOWAN
L CE
P001 26000 12000
P002 22000 10000
P003 12000 6000

a. To display the details of all WORKERs in descending order of DOB.


b. To display NAME and DESIG of those WORKERs, whose PLEVEL is either P001 or
P002.
c. To display the content of all the WORKERs, whose DOB is in between ’19-JAN-
1984’ and ’18-JAN-1987’.
d. To add a new row with the following:
19, ‘Daya Kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-Jul-1984’
e. SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
f. SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
g. SELECT Name, Pay FROM WORKER W, PAYLEVEL P
WHERE W.PLEVEL = S. PLEVEL AND P.ECODE < 13;
h. SELECT PLEVEL, PAY + ALLOWANCE FROM PAYLEVEL
WHERE PLEVEL = ‘P003’;

Integrate SQL with Python by importing


MySQLdb/mysql.connector
1. Create a table Student in a database ‘project’ as shown below:
RollNo int primary key
Name varchar(20)
Total int
Grade varchar(3)
a. Input Rollno, Name, Total marks and Grade and insert the record in a table Student.
b. Input Rollno and update the corresponding record in a table Student with the value
entered by the user.
c. Display all the records from a table Student.

2. Consider the table Product with following structure.

P_ID | ProductName | Manufacturer | Price


---------------------------------------------------
1 | Laptop | Dell | 1000.0
2 | Phone | Apple | 800.0
3 | Tablet | Samsung | 600.0

Write Python code to increase the price of all products by 50.


3. Create a table Student in a database ‘project’ as shown below:
RollNo int primary key
Name varchar(20)
Total int
Grade varchar(3)
a. Input Rollno and display the corresponding information from the table Student.
b. Input Rollno and delete the corresponding record from the table Student.
c. Display all the records of a grade entered by the user from the table Student.
d. Display all the records in descending order of total marks from the table Student.

You might also like