Soal Latihan Pyhton
Soal Latihan Pyhton
Soal Latihan Pyhton
will output 2
is erroneous
will return None
will output 4
9. The following snippet:
def func1(a):
return a ** a
def func2(a):
return func1(a)*func1(a)
print(func2(2))
is erroneous
will output 2
will output 4
will output 16
10. Which of the following lines properly starts a function
using two parameters, both with zeroed default values?
def fun(a=b=0):
fun fun(a,b=0):
fun fun(a=0,b):
def fun(a=0,b=0):
11. Which of the following statements is false?
The None value cannot be used as an argument of arithmetic operators
The None value can be assigned to variables
The None value may not be used outside functions
The None value can be compared with variables
12. What is the output of the following snippet?
def fun(x):
if x % 2 == 0:
return 1
else:
return
print(fun(fun(2)) + 1)
the code will cause a runtime error
1
None
2
13. What is the output of the following snippet?
def fun(x):
global y
y=x*x
return y
fun(2)
print(y)
2
4
None
the code will cause a runtime error
14. What is the output of the following snippet?
def any():
print(var + 1,end=”)
var = 1
any()
print(var)
22
21
11
12
15. Assuming that tuple is a correctly created tuple, the fact
that tuples are immutable means that the following instruction:
tuple[1] = tuple[1] + tuple[0]
is illegal
is fully correct
can be executed if and only if the tuple contains at least two elements
may be illegal if the tuple contains strings
16. What is the output of the following snippet?
list = [‘Mary’, ‘had’, ‘a’, ‘little’, ‘lamb’]
def list(L):
del L[3]
L[3] = ‘ram’
print(list(list))
[‘Mary’, ‘had’, ‘a’, ‘ram’]
[‘Mary’, ‘had’, ‘a’, ‘little’, ‘lamb’]
the snippet is erroneous
[‘Mary’, ‘had’, ‘a’, ‘lamb’]
17. What is the output of the following snippet?
def fun(x,y,z):
return x+2*y+3*z
print(fun(0,z=1,y=3))
3
the snippet is erroneous
0
9
18. What is the output of the following snippet?
def fun(inp=2,out=3):
return inp * out
print(fun(out=2))
6
4
2
the snippet is erroneous
19. What is the output of the following snippet?
dct = { ‘one’:’two’, ‘three’:’one’, ‘two’:’three’ }
v = dct[‘one’]
for k in range(len(dct)):
v = dct[v]
print(v)
two
three
(‘one’, ‘two’, ‘three’)
one
20. What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup = tup[1:-1]
tup = tup[0]
print(tup)
the snippet is erroneous
(2)
(2,)
2