PYHTON: Function Test
PYHTON: Function Test
a) Hello WorldWorldWorldWorldWorld
b) Hello World 5
c) Hello World,World,World,World,World
d) Hello HelloHelloHelloHelloHello
2.What is the output of the following piece of code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
a) 4
b) 5
c) 1
d) An exception is thrown
3. What is the output of the following code?
def foo():
total += 1
return total
total = 0
print(foo())
a) 0
b) 1
c) error
d) none of the mentioned
4. What is the output of the following?
i=0
while i <= 6 :
i += 1
if i % 3 == 0:
break
print("*")
a) *
b) **
c) ***
d) ****
e) *****
f) Syntax error
5.What is the output of the following code?
def foo(k):
k = [1]
q = [0]
foo(q)
print(q)
a) [0].
b) [1].
c) [1, 0].
d) [0, 1].
7. What is the output of the
following?
def func(a,b):
return a ** a
print(func(3,5))
a) 15
b) 25
c) Error
d) 125
e) 27
8. What is the output of the following?
var = 0
while var < 10:
var += 2
if var % 2 == 0:
continue
print("#")
a) ##
b) ####
c) null
d) Syntax error
e) None of the above
9. What is the output of the following?
def fun(x):
if x % 2 == 0:
return 2
else:
return
print(fun(2))+ 1)
a) None
b) Error
c) 1
d) 2
e) 0
10. What is the output of the following?
def fun(x):
global y
y=x*x
return y
fun(4)
print(y)
a) Error
b) 256
c) 64
d) 16
e) none
11. What is the output of the following?
def any():
print(var + 1,end='')
var = 1
any()
print(var)
a) 11
b) 12
c) Error
d) 21
e) 22
12. What is the output of the following?
var = 1
while var < 10:
print("#")
var = var << 1
a) ####
b) ###
c) ##
d) #
e) error
13. What is the output of the following?
print(thistuple)
Write the ouput of the following code.?
14. What is the output of the following?
def I():
s = 'abcdef'
for c in s[::2]:
yield c
for x in I():
print(x,end='')
a) Ab
b) Ef
c) Abc
d) Ace
e) Def
15. What is the output of the following?
def I(n):
s = '+'
for i in range(n):
s += s
yield s
for x in I(2):
print(x,end='')
a) ++
b) +++
c) ++++
d) +++++
e) ++++++
16. What is the output of the following?
def f(x):
if x == 0:
return 0
return x + f(x - 1)
print(f(3))
def o(p):
def q():
return '*' * p
return q
r = o(1)
s = o(2)
print(r() + s())
a) *
b) **
c) ***
d) ****
18. What is the output of the following?
name = ‘jack’
n=6
foo(name , n)
a) Syntax Error
b) Shahzad , 6
c) Shahzad , none
d) Shahzad , 8
e) None of the above
19. What is the output of the following?
name = ‘jack’
n=6
foo(name , n)
print(name , n)
a) Error
b) Shahzad , 8
c) Shahzad , 6
d) Jack , 6
e) None of the above
20. What is the output of the following?
def fun(x):
x += 1
return x
x=2
x = fun(x+1)
print(x)
a) 4
b) 6
c) 2
d) None
e) Invalid Syntax
21. What is the output of the following?
def foo(a,b):
if a == b:
return(a+b)*2
else:
return a+b
X = foo(1,3)
Y = foo(2,2)
print(X , Y)
a) 4 , 6
b) 3 , 6
c) 4 , 8
d) 2 , 6
e) None of the above
22. What is the output of the following?
def func(a,b):
return a ** a
print(func(2))
a) 4
b) 4.0
c) 2.0
d) error
23. What is the output of the following?
s1=[2, 4]
s2=[1, 3,5]
s3=list()
i=0
j=0
for i in s1:
for j in s2:
s3.append((i,j))
i-=1
j-=1
print(s3)
a) [(2, 1), (3, 3), (4, 5), (4, 1), (5, 3), (6, 5)]
b) [(2, 1), (3, 3), (4, 6), (4, 1), (5, 5), (6, 5)]
c) [(2, 1), (1, 3), (0, 5), (4, 1), (3, 3), (2, 5)]