Dhruv Sharma CS Practical File
Dhruv Sharma CS Practical File
SHALIMAR BAGH
COMPUTER SCIENCE
PRACTICAL FILE
2024-2025
1
INDEX PAGE
2
TOPIC-1
USER DEFINED FUNCTION
QUESTIONS
SOLUTION -
OUTPUT -
3
QUES - 2 Write a program using a user defined function myMean()
to calculate the mean of floating values stored in a list.
SOLUTION -
OUTPUT -
4
QUES - 3 Write a program using a user defined function that accepts
an integer and increments the value by 5. Also display the id of
argument (before function call), id of parameter
before increment and after increment.
SOLUTION -
OUTPUT -
5
QUES - 4 Write a program using a user defined function that displays
the sum of first n natural numbers, where n is passed as an
argument.
SOLUTION -
OUTPUT -
6
QUES - 5The company performs the following tasks to fix the selling price of
each tent.
1. Accept user requirements for the tent, such as
a) height
b) radius
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making the tent
4. Calculate the net payable amount by the customer that is
inclusive of the 18% tax. Write separate user defined functions for
part 2,3 and 4.
SOLUTION -
7
Output-
8
QUES - 6 Write a program that simulates a traffic light. The program should consist of the
following:
1. A user defined function trafficLight( ) that accepts input from the user, displays an error
message if the user enters anything other than RED, YELLOW, and GREEN. Function light() is
called and following is displayed depending upon return value from light().
a) “STOP, your life is precious” if the value returned by light() is 0.
b) “Please WAIT, till the light is Green“ if the value returned by light() is 1
c) “GO! Thank you for being patient” if the value returned by light() is 2.
2. A user defined function light() that accepts a string as input and returns 0 when the input is
RED, 1 when the input is YELLOW and 2 when the input is GREEN. The input should be passed as
an argument.
3. Display “SPEED THRILLS BUT KILLS” after the function trafficLight( ) is executed.
SOLUTION -
OUTPUT -
9
QUES - 7 Create a user defined module basic_math that contains the
following user defined functions:
1. To add two numbers and return their sum.
2. To subtract two numbers and return their difference.
3. To multiply two numbers and return their product.
4. To divide two numbers and return their quotient and print “Division by
Zero” error if the denominator is zero.
Also add a docstring to describe the module. After creating the module,
import and execute functions at shell prompt.
SOLUTION -
OUTPUT -
10
TOPIC-2
TEXT FILE
QUESTIONS
SOLUTION -
OUTPUT -
11
QUES - 9 Write a function in Python to read a text file line by line and
display each word separated by #.
SOLUTION -
OUTPUT -
12
QUES - 10 Write a function in Python to read a text file and display the number
of vowels/ consonants/ uppercase / lowercase characters in a file.
SOLUTION -
OUTPUT -
13
QUES - 11 Write a program in python to Reverse and display each line
of text.
SOLUTION -
OUTPUT -
14
QUES - 12 Write a program in python to display lines of text ending with ‘Y’
or ‘y’.
SOLUTION -
OUTPUT -
15
QUES - 13 Write a function in Python to read a text file and convert the
uppercase letter into lowercase and vice versa.
SOLUTION -
OUTPUT -
16
TOPIC-3
BINARY FILE
QUESTIONS
OUTPUT -
17
QUES - 15 Assuming that a binary file VINTAGE.DAT contains records of the
following type, {VNO, VDesc, price} write a function in PYTHON to read the data
VINTAGE.DAT and display those vintage vehicles, which are priced between 200000 and
250000.
SOLUTION -
OUTPUT -
18
QUES - 16 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.
SOLUTION -
OUTPUT -
Ques-17 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)
SOLUTION -
19
OUTPUT -
Ques-18 Write a function in Python to read each record of a binary file “items.dat”, find
and display those items which cost less than 2500. Assume that the file is created with
the help of objects of the following type:
{ ID:string, GIFT:string, Cost:integer}
SOLUTION -
20
OUTPUT -
Ques-19 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]
SOLUTION -
21
OUTPUT -
22
TOPIC-4
CSV FILE
QUESTIONS
SOLUTION -
23
24
25
OUTPUT -
26
27
Ques-21 A CSV file TEACHER.CSV has following data:
CODE,NAME,SUBJECT,DESIG,NOP
1001,ADITI JAIN,PHYS,HOD,20
Write an interactive menu driven to do the following (using CSV module):
● Read the CSV file and display details of teachers whose DESIG is either TGT or PGT
and SUBJECT is ENG; if no record is found then display a message 'Record not found in
the file'
● Read the CSV file and display details if DESIG is either PRT or TGT; at the end display
number of such records found in the file
● Exit from the menu and quit the program
SOLUTION -
28
OUTPUT -
29
30
TOPIC -5
STACKS
QUESTIONS
SOLUTION -
OUTPUT -
31
Ques-23 Write functions AddPlayer(player) and DeletePlayer(player) in python to
add and remove a player by considering them as push and pop operations in a
stack.
SOLUTION -
OUTPUT -
32
Ques-24 Monika 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:
1. Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value
(marks) is greater than 70.
2. Pop the content of the stack
3. Display the content of the stack.
SOLUTION -
33
OUTPUT -
34
TOPIC-6
MYSQL
ASSIGNMENT -1
Q-1 Write SQL Command for (a) to (o) and output of (p)
TABLE : GRADUATE
35
a. Create Database DB1 and Create Table Graduate in DB1 database.
SOLUTION-
36
c. List the names of those students who have obtained DIV I.
37
SOLUTION-
38
f.To insert a new 11th row in the GRADUATE table:(11,”KAJOL”, 300,
“Comp Sc”, 75, 1)
SOLUTION-
39
i.To display students details sorted by NAME.
SOLUTION-
SOLUTION-
40
k.To display student’s details whose average is between 50 to 60.
SOLUTION-
SOLUTION-
41
n.To display students details who are either PHYSICS or COMPUTER SC
graduates.
42
(ii) Select Name, Average from GRADUATE WHERE div=2;
43
44
MYSQL
ASSIGNMENT-2
Table: Loan_Accounts
45
B.Create Table / Insert Into-
46
4. Display the details of all the loans.
47
6. Display the details of all the loans with less than 40
installments.
48
E) Using NULL-
10. Display the details of all the loans whose rate of interest is
not NULL.
49
F.) Using DISTINCT Clause-
50
13. Display the details of all the loans started after 31-12-2008
for which the number of installments are more than 36.
14. Display the Cust_Name and Loan_Amount for all the loans
which do not have 36 installments.
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.
51
16. Display the details of all the loans which started in the year
2009.
18. Display the details of all the loans whose rate of interest is in
the range 11% to 12%.
52
19. Display the Cust_Name and Loan_Amount for all the loans
for which the number of installments are 24, 36, or 48. (Using IN
operator)
21. Display the details of all the loans whose rate of interest is in
the range 11% to 12%.(Using BETWEEN operator)
53
J.) Using LIKE Operator
22. Display the AccNo, Cust_Name, and Loan_Amount for all the
loans for which theCust_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’.
54
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.
55
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.
56
L. 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.
57
32. For each loan compute Interest as
(Loan_Amount*(Int_Rate/100)*Installments).
33. Delete the records of all the loans whose start date is before
2007.
58
35. Add another column Category of type CHAR(1) in the Loan
table.
59
MYSQL
ASSIGNMENT -3
Table:Worker
60
2. Create the table WORKER and add records as shown below. Write SQL
61
c. To display the details in ascending order of empno.
62
f. To display the number of employees in each department but
the number of employees should be less than 3.
63
3. Create a table EMPLOYEE with the following data in the Work database.
Write SQL commands for the statements (a) to (h).
Table: EMPLOYEE
64
b. To display the employee names in descending order of age.
65
d. To display the area and number of employees in each area.
66
f. To display grade and maximum, minimum and average salary
of each grade.
67
68
MYSQL
ASSIGNMENT -4
1 N2 Delhi
2 B1 Mumbai
3 N2 Mumbai
4 N1 Kolkata
5 B1 Delhi
69
for each customer.
b. Display the Customer Details for each customer who uses a Nokia
handset.
5. Create the following tables SENDER and RECIPIENT in Cust database. Write
SQLcommands for the statements (i) to (iv) and give outputs for SQL queries (v) to
(viii)
Table:Sender
70
SenderID SenderName SenderAddress SenderCity
Table:Recipient
71
c. Display the recipient details in ascending order of RecName.
GIVE OUTPUTS
72
f. SELECT A.SenderName, B.RecName FROM Sender A, Recipient B WHERE A.SenderID
= B. SenderID AND B.RecCity = ‘Mumbai’;
73
MYSQL
ASSIGNMENT -5
Table: CLIENT
74
j. To display the details of the products whose price is in the range 50 to 100 (Both
values included).
k. To display the ClientName, City from table Client, and ProductName and Price
from table Product, with their corresponding matching P_ID.
75
m. SELECT DISTINCT City FROM Client;
76
o. SELECT ClientName , Manufacturer FROM Product P, Client C WHERE
C.P_ID = P.P_ID;
6. (II) 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
77
ECODE NAME DESIG PLEVE DOJ DOB
L
Table: PAYLEVEL
PLEVE PAY ALLOWANCE
L
78
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’.
79
e. SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BYPLEVEL;
80
Practical Assignment -6
(Python-MySQL Connectivity)
81
82
83
84
Output-
85
a.Write Python code to increase the price of all products by 50.
86
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.
87
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.
88
89