Grade 12 CS Practice Material 2023-24
Grade 12 CS Practice Material 2023-24
Grade 12 CS Practice Material 2023-24
S.
Name of the Chapters Page.No
No
1. REVISION TOUR - I 1
2. REVISION TOUR - II 24
4. FILE HANDLING 90
PRACTICE QUESTIONS
*****************************************************************
THEORY QUESTIONS
def Disp(x=0,y):
print(x,y)
10. User can change the functionality of a built in functions.
11. The variable declared outside a function is called a global variable.
12. The following code is a valid code (T/F)_______?
def Disp(sub1,sub2):
print(sub1,sub2)
Disp(sub=100,sub2=89) #Calling
13. The default valued parameter specified in the function header
becomes optional in the function calling statement.
14. The following Python code is a example of Positional argument
(T/F)
def Swap(x,y):
x,y=y,x
p=90
q=78
Swap(p,q)#Calling
15. Default parameters can be skipped in function call?
16. Variable defined inside functions cannot have global scope?
17. A python function may return multiple values?
18. Positional arguments can follow keyword arguments?
19. If function returns multiple values, then it will return as List.
print(max_of_three(3, 6, -5))
25. By default if you return multiple value separated by comma, then it
is returned as
(a) List (b) Tuples (c) String (d) None of the above.
26. Find the output of following code :
x=100
def study(x):
global x
x=50
print(“Value of x is :”, x)
a. 100 b. 50 c. Error d. None of the above
Findoutput()
29. If a function doesn’t have a return statement, which of the
following does the function return?
(a) int (b) null (c) None
(d) An exception is thrown without the return statement
30. The values being passed through a function call statements are
called
(a) Actual parameter (b) Formal parameter
(c) default parameter (d) None of these
31. How many types of arguments are there in function?
(a) 1 (b) 2 (c) 3 (d) 4
3. Write down the python to swap the values of x and y for the
blank space in the line marked as Statement-3.
4. Mention the output for the line marked as Statement-4.
5. The missing code for the blank space in the line marked as
Statement-5.
def Put(z,y,x):
x*=y
y+=1
z*=(x+y)
print(x,'$',z,'%',y)
a=10
b=20
c=5
Put(a,c,b)
Get(a,b,c)
Put(b,a,c)
10. Predict the output of the Python code given below:
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end="#")
display(20)
print(value)
11. Write a function countNow(PLACES) in Python, that takes the
dictionary, PLACES as an argument and displays the names (in
uppercase)of the places whose names are longer than 5 characters.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New
York",5:"Doha"}
The output should be: LONDON NEW YORK
add()
c=15
print("In main:", c)
Output:
Inside add() : 12
In main: 15
What is the output if “global c" is not written in the function
add()?
13. Predict the output of the following code:
L=5
B=3
def getValue():
global L, B
L = 10
B=6
def findArea():
Area = L * B
print("Area = ", Area)
getValue()
findArea()
14. Predict the output of the following code:
def process_strings():
words = ['Python', 'Java', 'C++', 'JavaScript']
result = ['', '', '', '']
index = 0
for word in words:
if word[-1] in ['n', 't']:
result[index] = word.upper()
index += 1
else:
result[index] = word.lower()
index -= 1
print(result) process_strings()#calling function
X, NUM = 100, 1
OUTER(NUM, 1)
OUTER(NUM, 2)
print(NUM, "@", X)
17. Rewrite the correct program:
Def fun():
x = input("Enter a number")
for i in range[x):
if (int(s.fabs(x)) % 2== 0) :
print ("Hi")
Else:
print("Number is odd")
sum(10,20)
print("Total:",total)
19. Predict the output of the following code:
def hello():
a=['MDU','MS','CGL','TBM']
k=-1
for i in ['MDU','MS','CGL','TBM'][:-2]:
if i in ['A','E','I','O','U']:
a[k]=['MDU','MS','CGL','TBM'][k]
k+=1
else:
a[k]=['MDU','MS','CGL','TBM'][k]
k-=1
print(a)
hello()
20. Write a function in python named SwapHalfList(Array), which
accepts a list Array of numbers and swaps the elements of 1st
Half of the listwith the 2nd Half of the list, ONLY if the sum of
1st Half is greaterthan 2nd Half of the list.
Sample Input Data of the list
Array= [ 100, 200, 300, 40, 50, 60],
Output Array = [40, 50, 60, 100, 200, 300]
21. Predict the output of the following code:
L = [5,10,15,1]
G=4
def Change(X):
global G
N=len(X)
for i in range(N):
X[i] += G
Change(L)
for i in L:
print(i,end='$')
a,b = runme()
print(a, '#', b)
runme(a,b)
print(a+b)
27. Write a function Interchange (num) in Python, which accepts a
list num of integers, and interchange the adjacent elements of the
list and print the modified list as shown below: (Number of
elements in the list is assumed as even) Original List:
num = [5,7,9,11,13,15]
After Rearrangement num = [7,5,11,9,15,13]
28. Rewrite the corrected code and underline each correction.
def Tot (Number):
Sum=0
for C in RANGE (1, Number + 1):
Sum + = C
return Sum
print(Tot [3])
L=[32,10,21,54,43]
for c in range (4,0,-1):
a=L[c]
b=L[c-1]
print(Bigger(a,b),'@', end=' ')
34. What will be the output of following Python Code:
def change(num):
for x in range(0,len(num),2):
num[x], num[x+1]=num[x+1], num[x]
data=[10,20,30,40,50,60]
change(data)
print(data)
35. Write a function listchange(Arr,n)in Python, which accepts a list
Arr of numbers and n is an numeric value depicting length of the
list. Modify the list so that all even numbers doubled and odd
number multiply by 3 Sample Input Data of the list: Arr= [
10,20,30,40,12,11], n=6 Output: Arr = [20,40,60,80,24,33]
36. Predict the output of the following:
def Compy(N1,N2=10):
return N1 > N2
NUM= [10,23,14,54,32]
for VAR in range (4,0,-1):
A=NUM[VAR]
B=NUM[VAR-1]
if VAR >len(NUM)//2:
print(Compy(A,B),'#', end=' ')
else:
print(Compy(B),'%',end=' ')
display(20)#Calling
print(value)
40. Predict the output of the following code:
def f():
global s
s += ' Is Great'
print(s)
s = "Python is funny"
s = "Python"
f()
print(s)
Text="Good go Head"
Change_text(Text)
46. Write a function called letter_freq(my_list) that takes one
parameter, a list of strings(mylist) and returns a dictionary where
the keys are the letters from mylist and the values are the
number of times that letter appears in the mylist, e.g.,if the
passed list is as: wlist=list("aaaaabbbbcccdde")
then it should return a dictionary as{‘a’:5,’b’:4,’c’:3,’d’:2,’e’:1}
47. Write the output for the following python code:
def Quo_Mod (L1):
L1.extend([33,52])
for i in range(len(L1)):
if L1[i]%2==0:
L1[i]=L1[i] /5
else:
L1[i]=L1[i]%10
L=[100,212,310]
print(L)
Quo_Mod(L)
print(L)
NUM=[10,23,14,54,32]
for C in range (4,0,-1):
A=NUM[C]
B=NUM[C-1]
Alpha(A,B)
57. Write a function INDEX_LIST(L), where L is the list of elements
passed as argumentto the function. The function returns another
list named ‘indexList’ that stores theindices of all Non-Zero
Elements of L. For example: If L contains [12,4,0,11,0,56] The index
List will have - [0,1,3,5]
58. Predict the output of the code given below:
def Convert(Old):
l=len(Old)
New=" "
for i in range(0,1):
if Old[i].isupper():
New=New+Old[i].lower()
elif Old[i].islower():
New=New+Old[i].upper()
elif Old[i].isdigit():
New=New+"*"
else:
New=New+"%"
return New
Older="InDIa@2022";
Newer=Convert(Older)
print("New String is: ", Newer)
if e[0] == T_eno:
e[2]=float(input("enter new salary"))
f.seek(pos)
__________ # Statement 4
found=True
except:
f.close()
if found==True:
print("employee record found and updated")
else:
print("employee record not found and updating not
possible")
(i) Write the statement to import the needed module.
(ii) Write the statement to open the file named "emp.bin"
as per the need of the code.
(iii) Write the statement to store the position of the file
pointer.
(iv) Complete the blank with the statement to write the
object "e" into the file.
3. As a programmer, help Raj to successfully execute the given
task.
import _______# Line 1
def addCsvFile(UserName,PassWord):
f=open(' user.csv','____') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close()
def readCsvFile():
THEORY QUESTIONS
1. What are Data structures?
2. List out the various types of Data structure.
3. Differentiate between primitive and non-primitive data structres.
4. Define Stack.
5. Write the applications of stack.
6. Differentiate between Push and Pop operations in the context of
stacks.
7. At what situation Underflow occurs in Stack?
8. Is Overflow possible in Python in the context of stack?
9. What is meant by peek operation?
def pop_data():
if ________ ==0: #statement5
print("Empty Stack,Cant pop")
return -1
else:
Stack.______ #statement6
return pop_item
Stack=_______________________ # statement1
push_data ([20,11,30,15,2])
print(pop_data())
1. Identify the missing code in statement 1.
2. Identify the missing code in statement 2 for completing
the stop parameter in the for loop.
3. Identify the missing function in statement 3 for inserting
Data into the stack.
4. What will be the contents of stack which will be printed
in statement 4?
5. Identify the missing code in statement 5 in pop_data()
function.
6. Identify the missing code in statement 6 for popping the
element in the stack.
3- MARKS
1. 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.
2. Write a function in Python POP(Arr), where Arr is a stack
implemented by a list of numbers. The function returns the value
deleted from the stack.
3. Alam has a list containing 10 integers. You need to help him
create a program with separate user defined functions to perform
the following operations based on this list.
● Traverse the content of the list and push the even
numbers into a stack.
● Pop and display the content of the stack. For Example:
If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be: 38 22 98 56 34 12
For Example:
If the sample Content of the list is as follows:
N=[2, 131, 34, 56, 21, 379, 98, -22, 35, 38]
Sample Output of the code should be:
38 35 -22 98 21 56 34
6. Write the definition of a function POP_PUSH(LPop, LPush, N) in
Python.
The function should Pop out the last N elements of the list LPop
and Push them into the list LPush.
For example :
If the contents of the list LPop are [10, 15, 20, 30]
And value of N passed is 2,
then the function should create the list LPush as [30,20] And the
list LPop should now contain [10, 15]
For example:
If the dictionary Stu_dict contains the following data:
Stu_dict ={5:(87,68,89), 10:(57,54,61), 12:(71,67,90),
14:(66,81,80), 18:(80,48,91)}
After executing Push_elements(), Stk_ID should contain
[5,12,14,18]
After executing Pop_elements(), The output should be:
18
14
12
5
Stack Empty
*********************************************************************
PRACTICE QUESTIONS
THEORY QUESTIONS
1. Define Database.
2. Define DBMS and how it is different from RDBMS.
3. List out any two database software names.
4. Define the following: (i) Relation (ii) Tuple (iii) Attribute.
5. What do you mean by term Domain in context of RDBMS? What will
be the domain for an attribute called "Age" of voters of a village?
6. What is View?
7. What is the purpose of Key in RDBMS?
8. Differentiate the following with an example:
(i) Degree and Cardinality of the Relation.
(ii) Candidate Key and Primary Key.
(iii) Alternate Key vs Candidate Key.
(iv) Primary Key vs Alternate Key.
(v) Primary Key vs Foreign Key.
(ii) Now Abhay wants to remove a column price from the table
STORE. Write the query.
7. Mayank creates a table RESULT with a set of records:
Based on
the given table, write SQL queries for the following:
(i) Decrease the salary by 5% of personals whose allowance
is known.
(ii) Display Name and Total Salary (sum of Salary and
Allowance) of all personals. The column heading ‘Total
Salary’ should also be displayed.
(iii) Delete the record of personals who have salary greater
than 25000.
PRACTICE QUESTIONS
THEORY QUESTIONS
1. Define SQL.
2. Write the difference between Single row functions and multi
row functions with an example.
3. What is the referential integrity constraint?
4. List out Various commands available under DDL and DML.
5. Write the appropriate command for the following situations:
(i) To Show the structure of the table.
(ii) To Create table/database.
(iii) To List out an existing database name.
(iv) To open an existing database.
(v) To List out existing table name.
6. Define Constraints. List out its types.
7. Differentiate the following with an example:
(i) DBMS vs RDBMS (ii) DDL vs DML (iii) Char vs Varchar
(iv) Primary key vs Unique (v) Primary key vs foreign key
(vi) Default vs NOT NULL
8. Write the appropriate command for the following situation:
(i) To delete structure of the table.
(ii) To add a new attribute in a table.
(iii) To Eliminates redundant data from a Query Result.
(iv) To display the records in ascending order of an attribute.
(v) To modify the structure of the table.
(vi) To delete records of the table.
(vii) To modify the structure of the table.
(viii) To add primary key in an existing table.
What will be the output after the execution of the given query?
SELECT COUNT (DISTINCT NAME) FROM COSMETICS ;
(a) 5 (b) 6 (c) 4 (d) 2
73. If column “Salary” contains the data set {1000, 15000, 25000,
10000, 15000}, what will be the output after the execution of
the given query?
SELECT SUM(DISTINCT SALARY) FROM EMPLOYEE;
(a)75000 (b) 25000 (c) 10000 (d) 51000
74. With SQL, how can you return the number of not null record in
the Project field of “Students” table?
a) SELECT COUNT (Project) FROM Students
b) SELECT COLUMNS (Project) FROM Students
c) SELECT COLUMNS (*) FROM Students
d) SELECT COUNT (*) FROM Students
75. Find the output of the MySQL query based on the given Table –
COACH:
Query:
SELECT COUNT(GAME),AVG(SALARY) FROM COACH;
(a) 3 70000 (b) 4 35000 (c) 4 70000 (d) 3 35000
76. Which of the following set of functions is a valid set of
aggregated functions in MySQL?
(a) AVG(),ROUND(),COUNT() (b) MIN(),UPPER(),AVG()
(c) COUNT(),MAX(),SUM() (d) DATE(),COUNT(),LTRIM()
77. Aggregate functions can be used in the select list or the _____
clause of a select statement. They cannot be used in a ______
clause.
(a) Where, having (b) Having, where
(c) Group by, having (d) Group by, where
SELECT
SEC,AVG(MARKS) FROM STUDENT GROUP BY SEC HAVING
MIN(MARKS)>80;
(a) B 83 (b) A 84
(c) A 84 (d) A 83
B 83 B 80
87. What is the meaning of “HAVING” clause in SELECT query?
(a) To filter out the summary groups
(b) To filter out the column groups
(c) To filter out the row and column values
(d) None of the above
88. Select correct SQL query from below to find the temperature in
increasing order of all cites.
(a) SELECT city FROM weather ORDER BY temperature;
(b) SELECT city, temperature FROM weather;
(c) SELECT city, temperature FROM weather ORDER BY
temperature;
(d) SELECT city, temperature FROM weather ORDER BY
city;
89. The HAVING clause does which of the following?
(a) Acts EXACTLY like a where clause
(b) Acts like a WHERE clause but is used for columns
rather than groups.
(c) Acts like a WHERE clause but is used for group rather
than rows.
(d) Acts like a WHERE clause but is used for rows rather
than columns.
90. Which SQL statement do we use to find out the total number of
records present in the table ORDERS?
(a) SELECT * FROM ORDERS;
(b) SELECT COUNT (*) FROM ORDERS;
(c) SELECT FIND (*) FROM ORDERS;
(d) SELECT SUM () FROM ORDERS;
(i) SELECT
DISTINCT TID FROM TECH_COURSE;
(ii) SELECT TID, COUNT(*), MIN(FEES) FROM
TECH_COURSE GROUP BY TID HAVING
COUNT(TID)>1;
(iii) SELECT CNAME FROM TECH_COURSE WHERE
FEES>15000 ORDER BY CNAME;
(iv) SELECT AVG(FEES) FROM TECH_COURSE WHERE
FEES BETWEEN 15000 AND 17000;
7. Write the outputs of the SQL queries (i) to (iv) based on the
relations Teacher and Placement given below:
11. Write the output of SQL queries (a) and (b) based on the follwing
two tables DOCTOR and PATIENT belonging to the same
database:
13. Consider the following tables FACULTY and STUDENT. Write the
output for the MYSQL statement given below and state what type
of join is implemented.
SELECT * FROM FACULTY,STUDENT
(a) Write a query to change the fare to 6000 of the flight whose
FNO is F104.
(b) Write a query to display the total number of MALE and
FEMALE passengers.
(c) Write a query to display the NAME, corresponding FARE and
F_DATE of all passengers who have to START from DELHI.
(d) Write a query to delete the records of flights which end at end
MUMBAI.
**********************************************************
THEORY QUESTIONS
import mysql.connecotor as c
s=c.connect(host='localhost',user='a',password='a')
cur=c.cursor()
cur.execute('USE TRAVEL')
cur.execute("SELECT * FROM PASSENGERS")
Res=cur.fetchall()
for R in Res:
print(R[1])
s.close()
Consider the
ENO ENAME DEPT SALARY following
1 ALEX MUSIC 60000 information stored
2 PETER ART 67000 in the table: EMP
3 JOHNY MUSIC 65000
4 USHA ART 85000
**********************************************************
(a) Suggest and draw the cable layout to efficiently connect various
blocks of buildings within the Noida centre for connecting the
digital devices.
(b) Suggest the placement of the following device with
justification: i. Repeater ii. Hub/Switch
(c) Which kind of network (PAN/LAN/WAN) will be formed if
the Noida office is connected to its head office in Mumbai?
(d) Which fast and very effective wireless transmission medium
should preferably be used to connect the head office at Mumbai
with the centre at Noida?
(e) Suggest a protocol that shall be needed to provide Video
Conferencing solution between Block A to C.
(ii) Which device will you suggest to be procured by the company for
connecting all the computers within each of, their offices out of
the following devices? • Modem • Telephone • Switch/Hub
As a network expert, provide the best possible answer for the following
queries:
(ii) Suggest the most suitable place (i.e. buildings) to house the server
of this organization.
******************************************************************************
THEORY QUESTIONS
1. Define the following: (i) Module (ii) Package
2. What is meant by Library in Python?
3. Define Exception Handling in Python and explain its importance in
programming.
4. What is the Problem in the following code:
from import factorial
print(math.factorial(5))
5. Discuss common built-in exception types in Python and when they
might occur during program execution
6. How to handle the exceptions in Python?
7. Explain the purpose of the try, except, and finally blocks in Python's
exception handling mechanism.
8. Write the difference between IndexError and ValueError.
9. Consider the code given below and fill in the blanks:
11. Every
syntax error is an exception but every exception is
cannot be a syntax error. Justify your answer.
12. Describe the role of the raise statement in Python's
exception handling. Provide an example.
n-gl.com