Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

PracticeTest RevisionTour Functions

This document contains a practice exam for computer science with 19 multiple choice questions covering topics like functions, loops, lists, tuples, arguments, scope, and more. The questions test understanding of Python concepts like defining and calling functions, modifying lists, output of code snippets, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

PracticeTest RevisionTour Functions

This document contains a practice exam for computer science with 19 multiple choice questions covering topics like functions, loops, lists, tuples, arguments, scope, and more. The questions test understanding of Python concepts like defining and calling functions, modifying lists, output of code snippets, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPUTER SCIENCE

PRACTICE EXAM :Revision Tour, Functions


CLASS XII

DATED:03.07.2022

MAX TIME: 2hr


FULL MARKS:52

1. What are functions? Do function always return values? Explain with example.2+1+1

2. What will be the output for the following functions? 1

a) def fun1(x, y):


x=x+y
y=x–y
x=x–y
print(‘a=’, x)
print(‘b=’, y)
a=5
b=3
fun1(a,b)

b) def func(x,y=100): 1
temp = x + y
x += temp
if(y!=200):
print(temp, x,x)
a=20
b=10
func(b)
print(a,b)
func(a,b)
print(a,b)

3. How many times will Python execute the code inside the following while loop? 1

i=1
while i < 10000 and i > 0 and 1:
print (“Hello ...”)
i=2*i
4. 1+2

What can be the max and min values for first, second and third.

5. What will be the output of the following Python code? 2

a=[10,23,56,[78]]
b=list(a)
a[3][0]=95
a[1]=34
print(b)

a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]

Explain output to get marks for Q5.

6. What will be the output of the following Python code? 2


x=[1, 3, 6, [18]]
y=list(x)
x[3][0]=15
x[1]=12
print(y)

Explain output to get marks for Q 6.

7. def myFun(a, b): 2


def myFun1(c, d):
return c + d
return myFun1(a, b)
return a
result = myFun(12, 13)
print(result)

Explain output to get marks for Q 7.

8. What will be the output of the following Python code? 2


print (21//9%3, 2**2**3)

(a) 7 64
(b) 2 256
(c) 7 256
(d) 2 64

Explain output to get marks for Q 8.

9. What will be the output of the following python code? 2

a = [0, 1, 2, 3]
i = -2
for i not in a:
print(i)
i += 1

a) -2 -1
b) 0
c) error
d) none of the mentioned

Explain output to get marks for Q 9.

10. Predict the output of the following code fragment .1

L=[10,20,30,40,50,60]
L=L[1:10]+L[-10:3]
print(L)

11.Which of the following statements will create a tuple? 1

(a) Tp1 = (“a”,“b”)


(b) Tp1= (3) * 3
(c) Tp1= (“a”)+(“b”)
(d) All of the above

12. Differentiate between actual arguments and formal arguments?How many types of
formal arguments are there?Explain with example? 2+3+3

13. Which of the following function calls are illegal/legal and why? 3

def test( *a,c,b=5):


………..
……….

a)test(1,2,3)
b)test([2,3,4],b=6,c=5)

c)test(c=10,1,2,3,4,5)

14. Write a function part_reverse(<list>,start, end) to reverse elements in a list 3


where arguments are start and end index of the list part which is to be reversed.
Assume that start<end, start>=0 and end<len(list)

Sample Input Data of List:

my_list=[1,2,3,4,5,6,7,8,9,10]
Function Call = part_reverse(my_list,3,6)
Output is
my_list=[1,2,3,7,6,5,4,8,9,10]

15.What is LEGB rule? 2+2


c = 10
def add ():
global c
c=c+2
print ("Inside add():", c)
add ()
c=15
print ("In main:", c)

output:
Inside add() : 12
In main: 15

Consider the above program and justify the output. What is the output if
“global c “ is not written in the function add().

16. Look at the following code snippet and write the output. 2

a= [1, 2, 3, 4, 5]
for i in range (1, 5):
a[i-1] = a[i]
for i in range(0, 5):
print(a[i],end = “ ”)

a) 5 5 1 2 3
b) 5 1 2 3 4
c) 2 3 4 5 1
d) 2 3 4 5 5

17. What will be the output of the following code snippets: 2+2

A)
i=6
L=[1,2,3,4,6]
for i in L:
print(i)
B)
i=6
while i in L:
print(i)

Explain output to get marks for Q 17.


18.What will be the output of the following expressions 1.5+1.5

a) (3 == 4! =3)
b) ((3 == 4)!=3)

Without correct explanation no marks will be awarded for Q18.

19. What is the output of the following code snippet? 3

def ChangeVal (M, N):


for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3

L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")

a) 5#8#15#4#
b) 5#8#5#4#
c) 5#8#15#14#
d) 5#18#15#4#

Show dry run of the code to get marks

You might also like