Computer
Science
Practical File
Roll Number ___________________________
Class & Section_________________________
School_________________________________
___________________________________
Page 1
Index
S.
Program Title Signature
No.
1. Write a Python script to enter the marks of five subjects and calculate percentage
with grade. Grade conditions are:
Percentage Grade
91 to 100 A
81 to 90 B
71 to 80 C
61 to 70 D
Others E
2. Write a Python script to find and display largest of three integers. (Use nested if-else)
3. Write a menu driven Python script to calculate area of triangle, area of rectangle, area
of circle based on user choice.(use if-else, while loop)
4. Write a program to input the value of x and n and print the sum of the following
series:
• 1 + 𝑥 + 𝑥 2 + 𝑥 3 + 𝑥 4 + 𝑥 5 + . .. 𝑥 𝑛
• 1 − 𝑥 + 𝑥 2 − 𝑥 3 + 𝑥 4 − 𝑥 5 + . .. 𝑥 𝑛
𝑥2 𝑥3 𝑥4 𝑥5 𝑥𝑛
• 𝑥− + + − . ..
2 3 4 5 𝑛
𝑥2 𝑥3 𝑥4 𝑥5 𝑥𝑛
• 𝑥+ − + − . ..
2! 3! 4! 5! 𝑛
5. Write a program to determine whether a number is a perfect number, an Armstrong
number or a palindrome.
6. Write a Python script to sum and display N terms of Fibonacci Series using function.
The 'N' should be passed to function as parameter.
7. Write a Python script to print the table of a given number. The given number should
be passed to a function as parameter.
8. Write a Python script to calculate the factorial of a given number using function. The
number should be passed as parameter and function should return the value of
factorial.
9. Write a Python script to count number of vowels, number of digits, number of
uppercase letters, number of lowercase letters present in a string. (Use function)
10. Write a Python script to check whether an entered string is a palindrome or not. (Use
function)
11. Write a Python script to print largest and smallest element present in a list without
using min() and max() built in functions. The list should be passed as parameter to a
function.
12. Write a Python script to swap adjacent elements of a list using function. The list
should be passed as a parameter to the function.
13. Write a Python script to create a dictionary to store AQI(Air quality index) for ten
cities of India and display best and worst city name based of AQI. Use Dictionary as
an argument to a function.
Page 2
14. Write a Python script to count frequency of each letter present in string. (use
dictionary to store counting with function)
15. Write a Python script to store number of covid-19 patients based on their countries,
then display number of covid-19 patients country wise.(use dictionary and function)
Use Country name as key and value as number of covid-19 patients.
DATA FILES (TEXT FILES and BINARY FILES)
16. Write a Python script to count number of characters, number of uppercase letters,
number of lowercase letters, number of vowels, number of digits, number of spaces
and number of other characters present in disk file 'story.txt'
17. Write a Python script to replace all occurrence of 'he' with 'she' in a text file
'STORY.TXT'
18. 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
19. Write a function in PYTHON to count the number of lines ending with a vowel from a
text file 'STORY.TXT'
20. Read a text file(story.txt) line by line and display each word separated by a #.
21. Given a binary file “STUDENT.DAT”, containing records of the following type:
[Admno, Name, Per]
Where these three values are:
Admno – Admission Number of student (integer)
Name -- Name of student (string)
Per – Marks percentage of student (float)
Write a Python script to write the details of students in a binary file. Also read contents
of the file “STUDENT.DAT” and display the details of those students whose percentage
is above 75.
22. Write a menu driven program for the binary file ITEMS.DAT storing the objects of
following type:
{"ID":integer, "GIFT":string, "Cost":float}
i) To write the objects of above type in binary file
ii) To read and display all the objects
iii) To update an object for a given ID.
iv) To delete an object for a given ID.
CSV FILES
23. Write a menu driven program to read/write data in CSV file(emp.csv) also display
number of records in CSV file.
Suppose CSV file contain following data:
Page 3
id,name,email,age,designation
1,John,[email protected],24,programmer
2,Bob,[email protected],34,designer
3,Mary,[email protected],43,sales
4,Raj Kumar, [email protected],34,data analysist
5,Kerry, [email protected],24,developer
24. Write a Program to read CSV file(authors.csv) and display the details those authors
who have written their book in the year 1991.
Suppose CSV file contain following data:
Programming language, Designed by, Appeared, Extension
Python, Guido van Rossum, 1991, .py
Java, James Gosling, 1995, .java
C++, Bjarne Stroustrup, 1985, .cpp
C, Yashwant Kanetkar, 1980, .c
25. program to read and display CSV file(authors.csv) without heading and avoid blank
lines between records.
DATA STRUCTURE
26. Write a program to implement a stack using a list.
SQL STATEMENTS
27. In a database 'Company' create a table 'Customer' of following columns with
appropriate datatypes and insert the records:
Customer
Id Name Address Phone NoofVisit
1 Ankit Jain C-9, Yamuna Vihar, Delhi 9458795823 4
2 Simranjeet G-89, Bandra, Mumbai 9857589696 3
3 Sumedha Madan H-90, Janakpuri, Delhi 7856987589 2
4 Simranjeet R-78, Worli, Mumbai 9658758963 6
5 John T-90, California Null 12
With reference to above table, write the SQL statements:
(i) To display customer name and address of all customers living in Mumbai.
(ii) To display the details of all customer in descending order of their names.
(iii) To name of those customer whose number of visits in the range of 3 and 10.
(iv) To display Name of those customer whose phone is empty.
(v) SELECT DISTINCT NAME FROM CUSTOMER WHERE ID>=3;
(vi) SELECT COUNT(*) FROM CUSTOMER;
28. Create another table 'Bill' under 'company' database with appropriate datatypes and
insert the records. Bill
BillNo Id Bill_Amount
1 2 12500
2 1 15000
3 2 16000
4 3 25000
5 4 1400
Page 4
With reference to above tables(Customer and Bill), write the SQL statements:
(i) To display Cartesian product of Customer and Bill tables.
(ii) To display customer name and bill amount of all customers living in Delhi.
(iii) To display Equi-Join of Customer and Bill tables.
(iv) To display Natural Join of Customer and Bill tables.
(v) Increase the bill amount by 1000 of customers having id as 1.
(vi) Add a new column "Remarks" of Varchar(20) in remarks table.
(vii) Add Billno as primary in Bill table.
(viii) SELECT MAX(BILL_AMOUNT), MIN(BILL_AMOUNT) FROM CUSTOMER, BILL
WHERE CUSTOMER.ID = BILL.ID ;
(ix) SELECT ID, SUM(BILL_AMOUNT) FROM BILL Group by Id;
(x) SELECT NAME, BILL_AMOUNT FROM CUSTOMER, BILL WHERE
CUSTOMER.ID=BILL.ID;
29. In a database 'School' create a table "Teacher" with appropriate datatypes and insert
the records:
TID TName Subject Gender Salary DOJ
101 Rakesh Comp. Sc, M 45000 2000-02-12
102 Smith Maths M 55000 2004-01-03
103 Sangeeta History F 50000 2010-03-12
104 Simran Comp. Sc. F Null 2018-10-02
105 Anil Maths M 56000 2010-12-01
With reference to above table write the SQL statements:
(i) To display Name, salary for those teachers who are teaching maths.
(ii) To display Name of female teachers who teaches computer science subject.
(iii) To display teachers name and date of join who teachers either Computer
science or History or English.
(iv) To display details of those teachers who have join in march month.
(v) To set the salary as 40000 for those whose salary is not decided.
(vi) Display the structure of teacher table.
(vii) Delete those records who have joined before 1st Jan. 2020
(viii) SELECT SUBJECT, MAX(SALARY) FROM TEACHER
GROUP BY SUBJECT;
(ix) SELECT MIN(SALARY) FROM TEACHER WHERE GENDER='M';
(x) SELECT TNAME, SUBJECT FROM TEACHER
WHERE SUBJECT LIKE '%Sc.';
30. Create another table 'Student' under 'School' database with appropriate datatypes and
insert the records.
Page 5
Student
RNo SName Class TID
1 Ankur Gupta XI 101
2 Deepa Sharms XII 104
3 Ankit XI 102
4 Rahul Sharma XII 102
5 Raman Kumar XII 105
With reference to above tables, write the SQL statements:
(i) Add RNo as primary key in Student table.
(ii) To display student names having exactly five characters in their length.
(iii) To display Name, salary for those teachers who are teaching class XI.
(iv) To display name of those students who are taught by teacher id as 102.
(v) To display Name of students and their class whose taught by female
teachers only.
(vi) To display teachers name, students name and class of student with
corresponding matching TID.
(vii) Modify the width of 'Sname' column as 25.
(viii) SELECT MAX(SALARY) FROM TEACHER WHERE GENDER='M';
(ix) SELECT SNAME, TID FROM STUDENT WHERE CLASS='XII'
ORDER BY SNAME DESC;
(x) SELECT TNAME, SUBJECT, SNAME FROM TEACHER, STUDENT WHERE
TEACHER.TID=STUDENT.TID AND CLASS='XI';
PYTHON/MYSQL CONNECTIVITY
31. Write a Program to create a table 'EMP' under 'COMPANY' database with following
structure:
First_Name char(20) Not Null,
Last_Name char(20),
Age int(3)
Gender char(1)
Income Float(9,2)
DOJ date
Use MySQL database connectivity with Python.
32. Write a program to insert at least 5 records in the table created in previous program,
also display its content on the screen using MySQL database connectivity with
Python.
33. Write a program to display those employee records who have joined before 1 st
January, 2010 from 'EMP' using MySQL database connectivity with Python. Also
count number of such employees.
34. Write a program to set date of join as 1st January, 2017 for those employees whose
date of join not entered, using MySQL database connectivity with Python.
35. Write a program to delete those records whose age more than 60 years from 'EMP'
table using MySQL database connectivity with Python.
Page 6