0% found this document useful (0 votes)
17 views

CS Practical file Class 12th.docx

Uploaded by

ashjoddd7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

CS Practical file Class 12th.docx

Uploaded by

ashjoddd7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

DLDAV MODEL SCHOOL, SHALIMAR BAGH

Computer Science
PRACTICAL
FILE

➡ Name - Aniket Barkataki 5


➡ Class – XII-B
➡ Session - 2024-202511111111
➡ Roll No. - 4 521155115511111
111
INDEX

1.​User-Defined Functions
2.​Text File
3.​Binary File
4.​CSV File
5.​Stacks
6.​SQL Assignment 1
7.​SQL Assignment 2
8.​SQL Assignment 3
9.​SQL Assignment 4
10.SQL Connectivity

2
Topic I​
User-Defined Functions

1. Write a program using a user defined function calcFact() to calculate and


display the factorial of a number num passed as an argument.

ANS.

3
2. Write a program using a user defined function myMean() to calculate the
mean of floating values stored in a list.

ANS.

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.

ANS.

4
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.

ANS.

5
5. The 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.

ANS.

6
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.

ANS.

7
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.

ANS.

8
9
Topic II​
Text File

Note - All Func calls are shown together in the last image
-​ Same Story.txt has been used for all Ques
(Additions have been made for Q12)

8. 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.

ANS.

10
9. Write a function in Python to read a text file line by line and display each
word separated by #.

ANS.

11
10. Write a function in Python to read a text file and display the number of
vowels/ consonants/ uppercase / lowercase characters in a file.

ANS.

12
11. Write a program in python to Reverse and display each line of text.

ANS.

12. Write a program in python to display lines of text ending with ‘Y’ or ‘y’.
ANS.

13
13. Write a function in Python to read a text file and convert the uppercase
letter into lowercase and vice versa.
ANS.

14
All Func Calls-

Topic III​
Binary File

Note - All Func calls are shown together in the last image
-​ All Ques are done in the same file therefore pickle
is shown to be imported once (i.e. Q14)
-​ All Passed arguments are shown along with the Func
calls

14. Write a function in PYTHON to search for a BookNo from a binary file
“BOOK.DAT”, after creating the binary containing the records of the
following type: {BookNo":value, "Book_name":value} The
BookNo is an integer.

ANS.

15
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.

ANS.

16
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.

ANS.

17
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)

ANS.

18
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}

ANS.

19
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]

ANS.

20
All Func calls-

21
Topic IV​
CSV File

Note - All Func calls are shown together in the last image
-​ All Ques are done in the same file therefore csv is
shown to be imported once (i.e. Q20)

20. A CSV file TEACHER.CSV has following data:


TCODE,TNAME,SUBJECT,DESIG,NOP
1001,ADITI JAIN,PHYS,HOD,20
Write an interactive menu driven to do the following (using CSV module):
● Append following records(lines) in the file TEACHER.CSV
1011,MANOJ KUMAR,ENG,PGT,24
1012,NAMITA KAUR,ENG,TGT,28
1013,PRATAP SHINDE,ENG,TGT,29
1014,GUARI KAPOOR,ENG,PRT,30
1015,HITESH DESAI,MATH,HOD,20
1016,RAKESH YADAV,MATH,PGT,26
1017,ISHITA DASH,MATH,TGT,29
1018,DILIP MATHUR,MATH,TGT,27
1019,NUPUR CHACKO,MATH,PRT,30
1020,MANAS KHER,PHYS,PRT,30
● Read and display the CSV file; at the end display number of records(lines)
present in the file
● Read the CSV file and display details if DESIG is HOD; at the end display
number of such records (lines) found in the file
● Read the CSV file and display details if DESIG is PGT and SUBJECT is
either PHYS or CHEM; if no record found in the CSV file then display a
message 'Record not found in the file'
● Exit from the menu and quit the program

ANS.

22
23
24
25
26
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

ANS.

27
28
29
ALL Func Calls-

30
Topic V​
Stacks

22. Write a function in Python that reverses a string using Stack data structures.

ANS.

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.

ANS.

31
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.
32
ANS.

33
Topic VI​
SQL Assignment - 1

Q-1 Write SQL Command for (a) to (o) and output of (p)
TABLE : GRADUATE
S.N NAME STIPEND SUBJECT AVERAGE DIVISI
O ON
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP Sc 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CHEMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP Sc 62 I
10 VIKAS 400 MATHS 57 II

34
a. Create Database DB1 and Create Table Graduate in DB1 database.

35
b. Insert 10 rows in Graduate table.

c. List the names of those students who have obtained DIV I.

36
d. Display a report, listing NAME, STIPEND, SUBJECT and amount of
stipend received in a year assuming that the STIPEND is paid every month.

e. To display students details who are studying math.

37
f. To insert a new 11th row in the GRADUATE table:(11,”KAJOL”, 300, “Comp
Sc”, 75, “I”).

g. Add a new column GRADE of character type.

38
h. Display Name and division only in the Graduate table.

i. To display students' details sorted by NAME.

39
j. To display students details sorted by NAME in descending order.

k. To display student’s details whose average is between 50 to 60.

l. Display student RUBINA’s details.

40
m. Delete KAJOL’s details from the table.

n. To display students details who are either PHYSICS or COMPUTER SC


graduates.

41
o. Give the output of following sql statement based on table GRADUATE:-

i.)Select * from GRADUATE where SUBJECT=”PHYSICS”;

ii.)Select Name, Average from GRADUATE WHERE div=’II’;

iii.)Select Name, Average from GRADUATE where AVERAGE>=65;

42
iv.)Select distinct SUBJECT from GRADUATE;

Practical Assignment -2 (SQL


Commands)

1. Consider a database LOANS with the following table:

Table: Loan_Accounts

Cust_Name Loan_Amount Installments Interest


Int_Rate
Start_Date
AccNo

1 19-07-
R. K. Gupta 300000 36 12.00
2009

2 22-03-
S. P. Sharma 500000 48 10.00
2008

3 08-03-
K. P. Jain 300000 36 NULL
2007

43
4 06-12-
M. P. Yadav 800000 60 10.00
2008

5 03-01-
S. P. Sinha 200000 36 12.50
2010

6 05-06-
P. Sharma 700000 60 12.50
2008

7 05-03-
K. S. Dhall 500000 48 NULL
2008

I.) Write SQL commands for the tasks 1 to 35:-

A.)Create Database and use it-

1. Create the database LOANS.

44
2. Use the database LOANS.

B.)Create Table / Insert Into-

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

45
C.) Simple Select

4. Display the details of all the loans.

5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.

D.) Conditional Select using Where Clause-

6. Display the details of all the loans with less than 40 installments.

46
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.

E) Using NULL-

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

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

F.) Using DISTINCT Clause-

11. Display the amounts of various loans from the table Loan_Accounts. A loan
amount should appear only once.

48
12. Display the number of installments of various loans from the table
Loan_Accounts. An installment should appear only once.

G.) Using Logical Operators (NOT, AND, OR)-

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.

49
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
to500000.

18. Display the details of all the loans whose rate of interest is in the range 11%
to 12%.

50
H.) Using IN Operator

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)

I.) Using BETWEEN Operator

20. Display the details of all the loans whose Loan_Amount is in the range
400000 to 500000. (Using BETWEEN operator)

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

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’.

52
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.

K.) Using ORDER BY clause

27. Display the details of all the loans in the ascending order of their
Loan_Amount.

53
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.

L.) Using UPDATE, DELETE, ALTER TABLE

30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
54
31. Increase the interest rate by 0.5% for all the loans for which the loan amount
is more than 400000.

55
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.

56
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.

57
Practical Assignment -3 (SQL Commands)

Q1. Create Database Work and activate it.

Table:Worker
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

58
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.

59
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 the number of


employees should be less than 3.

60
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 in the Work database.
Write SQL commands for the statements (a) to (h).

Table: EMPLOYEE
No Name Salary Area Age Grade Dept

711 KESHAR 40000 WEST 45 C CIVIL

61
262 KIRTI 35000 SOUTH 38 A ELEC

693 KRIPPLE 60000 NORTH 52 B CIVIL

724 ARYAN 38000 NORTH 29 B CIVIL

705 SAMSO 42000 EAST 35 A COMP


N

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.

62
c. To display the grade and number of employees in each grade.

d. To display the area and number of employees in each area.

63
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 the grade and the number of employees in each grade where the
number of employees are more than two.

64
Practical Assignment -4 (SQL
Commands)

4. Create Database Cust and create two tables HANDSETS and CUSTOMER in it
as given below:

Table:- Handsets
SetCode SetName TouchScreen Phone Cost

N1 Nokia 2G N 5000

N2 Nokia 3G Y 8000

B1 BlackBerry 2G N 14000

Table:- Customer
CustNo SetNo CustAddress

1 N2 Delhi

2 B1 Mumbai

3 N2 Mumbai

4 N1 Kolkata

5 B1 Delhi

65
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’;

66
5. Create the following tables SENDER and RECIPIENT in Cust database. 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

67
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.

68
d. Display the number of recipients in each city.

GIVE OUTPUTS:-

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’;

69
g. SELECT RecName, RecAddress FROM Recipient Where RecCity NOT IN
(‘Mumbai’,’Kolkata’);

h. SELECT RecID, RecName FROM Recipient Where SenderID = ‘MU02’ OR


SenderID = ‘ND50’;

70
Practical Assignment -5
(SQL Commands)

Q6(I).Create 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
P_ID ProductName Manufacturer Price

TP01 Talcum Powder LAK 40

FW05 Face Wash ABC 45

BS01 Bath Soap ABC 55

SH06 Shampoo XYZ 120

FW12 Face Wash XYZ 95

71
Table:- CLIENT
C_ID ClientName City P_ID

1 Cosmetic Shop Delhi FW05

6 Total Health Mumbai BS01

12 Live Life Delhi SH06

15 Pretty One Delhi FW12

16 Dreams Bangalore TP01

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

j. To display the details of the products whose price is in the range 50 to 100
(Both values included).

72
k. To display the ClientName, City from table Client, and ProductName and Price
from table Product, with their corresponding matching P_ID.

l. To increase the price of all products by 10.

m. SELECT DISTINCT City FROM Client;

73
n. SELECT Manufacturer , MAX(price) , MIN(Price), COUNT(*)FROM Product
GROUP BY Manufacturer;

o. SELECT ClientName , Manufacturer FROM Product P, Client C WHERE C.P_ID


= P.P_ID;

p. SELECT ProductName, Price * 4 FROM Product; WHERE P_ID = ‘TP01’ OR


P_ID = ‘SH06

74
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
ECODE NAME DESIG PLEVEL DOJ DOB

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
PLEVEL PAY ALLOWANCE

P001 26000 12000

P002 22000 10000

7P003 12000 6000

75
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’.

76
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;

77
g. SELECT Name, Pay FROM WORKER W, PAYLEVEL P WHERE W.PLEVEL = P.
PLEVEL AND W.ECODE < 13;

h. SELECT PLEVEL, PAY + ALLOWANCE FROM PAYLEVEL


WHERE PLEVEL = ‘P003’;

78
79
80
a. Input Rollno, Name, Total marks and Grade and insert the record in a
table Student.

81
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.

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

83
a. Input Rollno and display the corresponding information from the table
Student.

b. Input Rollno and delete the corresponding record from the table Student.

84
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.

85

You might also like