COMPUTER SCIENCE
PRACTICAL FILE
Session 2024 – 25
Submitted to : Ms. Swati Yadav
Submitted by –
Name : ARYAN DHIMAN
Class : XII-E
Roll Number : 6
Page | 1
1) Write a program to create a user defined function that will accept a list of numbers as
parameter and will return a tuple of all prime numbers present in that list.
Input –
Output-
Page | 2
2) Write a program to create a list of lists for storing employee details (name, age,
department and salary), for example emp=[[„Rajnish‟,36,‟Testing‟,45000],
[„Amrita‟,45,‟HR‟,50000]] emp will be declared globally. In this program create
following functions:
a. To add a new employee detail in list, function name will be add_emp(empdata), where
parameter empdata is list of employee details (name, age, department and salary)
b. To display student details in tabular for as given below, show_employee(emp) where
emp is list of employees: Name Age dep Salary Rajnish 16 testing 45000 Amrita 15 HR
50000
Input –
Output –
Page | 3
3) Define a function that will take two numbers as parameter Sum_of_series(x,n) and will
evaluate and print sum of following series: X+x2/2! + x3/3! +x4/4! …….xn/n!
Input -
Output -
Page | 4
4) Write a program to create a list of numbers, where numbers will be generated randomly.
Number should be in between an upper limit and lower limit where upper limit and lower
limit will be taken as input.
Input -
Output-
Page | 5
5) Write program to read a text file in python and print its content.
Input -
Output-
Page | 6
6) Given a binary file “STUDENT.DAT”, containing records of the following type:
[S_Admno, S_Name, Percentage] Where these three values are: S_Admno – Admission
Number of student (string) S_Name – Name of student (string) Percentage – 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.
Input-
Output -
Page | 7
7) Assuming the tuple Vehicle as follows: ( vehicletype, no_of_wheels) Where vehicletype
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.
Page | 8
8) Assuming that a text file named TEXT1.TXT already contains some text written into it,
write a function named vowelwords(), that reads the file TEXT1.TXT and creates a new
file named TEXT2.TXT, which shall contain only those words from the file TEXT1.TXT
which don‟t start with an uppercase vowel (i.e., with „A‟, „E‟, „I‟, „O‟, „U‟). For example,
if the file TEXT1.TXT contains Carry Umbrella and Overcoat When It rains Then the
text file TEXT2.TXT shall contain Carry and When rains
Output -
Page | 9
9) Write a function in PYTHON to count the number of lines ending with a vowel from a
text file “STORY.TXT‟.
Ouput -
Page | 10
10) Write a function in PYTHON to count and display the number of words starting
with alphabet „A‟ or „a‟ present in a text file “LINES.TXT”. Example: If the file
“LINES.TXT” contains the following lines, A boy is playing there. There is a
playground. An aeroplane is in the sky. Are you getting it? The function should display
the output as 5.
Page | 11
11) Write a program in Python that defines and calls the following user-defined
functions: (i) AddRecord() – To accept and add data of Mobile phones to a CSV file
„Mobile_Phones.csv‟. Each record consists of a list with field elements as ModelNo,
MobileName, Manufacturer and Price to store model number, mobile name,
manufacturer and price respectively. (ii) Find() – To search the records of mobiles
manufactured by Apple present in the CSV file named „Mobile_Phones.csv‟.
Page | 12
Output -
Enter Model Number: iPhone13
Enter Mobile Name: iPhone 13 Pro
Enter Manufacturer: Apple
Enter Price: 99999
Record added successfully!
Page | 13
12) Write a program to write data in CSV file of a customer as follows: [customer_id,
customer_name, membership_type ]
Page | 14
13) Write a menu based program to store customer data of a bank. Data will be as
follows: [accno, name, address, balance,branch] Menu will be as follows: 1. Add a new
customer detail 2. Update a customer detail 3. Delete a customer detail 4. Search a
customer with accno 5. Display data of all customers 6. Exit
Output above -
Input above
Page | 15
14) A list contains the following record of a Hostel: [Hostel_No, Total_Students,
Total Rooms]
Write the following user defined functions to perform given operations on the stack
named „Hostel‟: (i) Push_element() - To push an object containing Hostel_No and Total
Students along with Total Rooms to the stack (ii) Pop_element() - To pop the objects
from the stack and display them. Also, display “Stack Empty” when there are no
elements in the stack.
Page | 16
15) Write a program to implement a Stack for book_details (book name : book price)
where book name is a key and book price is value. Write a function in Python,
Push(book_details) where book_details is a dictionary containing the details of books–
{book_name : book_price}. The function should push the names of those books in the
stack which have price greater than 500. Also display the count of books pushed into the
stack. For example: If the dictionary contains the following data:
books={"Python":560,"Java":450,"MySQL":330,"Web Development":725} The stack
should contain Python and Web Development. The output should be: The count of books
in the stack is 2.
Page | 17
16) Write a program to take two number as input and display any random number
between those two numbers.
Page | 18
17) Write a program to create a simple chatbot using dictionary to store data and
random number to generate response.
Page | 19
18) Write a program to take a number as input and display its square root using
function of math module
Page | 20
19) Write a program to take a float with 5 decimal digits as input and display after
rounding off that value to 2 decimal places using function of math module.
Page | 21
20) Write the code to reads the following record from the table named Employee and
displays only those records who have a Salary greater than 75000: EmpNo – integer
EmpName – string Designation – string Salary – integer Note the following to establish
connectivity between Python and MySQL: a. Username is root b. Password is sales_emp
c. The table exists in a MySQLdatabase named “Office”.
Page | 22
21)
1. Query to display the average salary of employees in the "Accounts" department
SELECT AVG(Salary) AS AverageSalary
FROM Employee
WHERE Department = 'Accounts';
-- 2. Query to display the sum of salary of all employees
SELECT SUM(Salary) AS TotalSalary
FROM Employee;
-- 3. Query to add a column office_site with VARCHAR and size 60 in the EMPLOYEE
table
ALTER TABLE Employee
ADD office_site VARCHAR(60);
-- 4. Query to display all data of employees whose name starts with "D"
SELECT *
FROM Employee
WHERE EmpName LIKE 'D%';
-- 5. Query to display details of all employees in order of their salary
SELECT *
FROM Employee
ORDER BY Salary;
-- 6. Query to display the average salary of employees under manager "Vardhaman"
SELECT AVG(Salary) AS AverageSalary
FROM Employee
WHERE Manager = 'Vardhaman';
Page | 23
-- 7. Query to delete the manager column from the Employee table
ALTER TABLE Employee
DROP COLUMN Manager;
-- 8. Query to update the salary of employee "E345" to ₹35000
UPDATE Employee
SET Salary = 35000
WHERE EmpNo = 'E345';
-- 9. Query to delete the data of employee "Mohan" from the Employee table
DELETE FROM Employee
WHERE EmpName = 'Mohan';
-- 10. Query to count the number of employees department-wise
SELECT Department, COUNT(*) AS EmployeeCount
FROM Employee
GROUP BY Department;
-- 11. Query to show employee details who do not have any manager
SELECT *
FROM Employee
WHERE Manager IS NULL;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Page | 24