PracticeTest RevisionTour Functions
PracticeTest RevisionTour Functions
DATED:03.07.2022
1. What are functions? Do function always return values? Explain with example.2+1+1
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.
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]]
(a) 7 64
(b) 2 256
(c) 7 256
(d) 2 64
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
L=[10,20,30,40,50,60]
L=L[1:10]+L[-10:3]
print(L)
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
a)test(1,2,3)
b)test([2,3,4],b=6,c=5)
c)test(c=10,1,2,3,4,5)
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]
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)
a) (3 == 4! =3)
b) ((3 == 4)!=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#