Python - Final Exam by Ethio Exams
Python - Final Exam by Ethio Exams
JOIN US ON TELEGRAM
@QesemAcademy
Multiple-choice
1.To repeat a fixed number of times use a
answer choices
A while loop
B for loop
C if loop
D indentation
2. Multiple-choice
To repeat until a particular condition is true use
answer choices
A while loop
B for loop
C if loop
D indentation
Q 4 - What is output of following code −
def func(n):
if(n==1):
return 1;
else:
return(n+func(n-1))
print(func(4))
A - 12
B - 10
C-9
D - 11
A - L.insert(2,6)
B - L.insert(3,6)
C - L.add(3,6)
D - L.append(2,6)
class Demo:
def __init__(self,d):
self.d=d
def print(self):
print(d)
a = Demo(''Hello'')
a.print()
A - You cannot use print(self) as a function name.
D - Syntax Error.
def func1(n):
if(n==0):
return 0
else:
return(n+func1(n-1))
def func2(n, result):
if(n==0):
return(result)
else:
return(func2(n-1, n+result))
print(func1(4))
print(func2(4,0))
A - Func1 is tail recursion.
Q 8 - Which event among them is fired when the right mouse button is released?
A - <ButtonReleased>
B - <ButtonPressed>
C - <ButtonReleased-3>
D - <ButtonPressed-3>
A - Canvas.entered(Enter, p)
B - Canvas.entered(''<Enter> '',p)
C - Canvas.bind(''<key> '',p)
D - Canvas.bind(key,p)
B - Website
C - ('TutorialsPoint' , 'website')
b. float(10)
c. int(10)
d. float(10.8)
Q-11: Consider the code block below. What happens when you run this program?
repeat_lyrics()
def repeat_lyrics():
print_lyrics()
print_lyrics()
def print_lyrics():
print("I'm a lumberjack, and I'm okay.")
print('I sleep all night and I work all day.')
A. 5
B. 10
C. 25
D. 32
E. 3125
13: Consider the following Python code. What does this code print?
A. 0
B. 3
C. 7
D. 1
14. Which of the following would NOT work as a variable name?
A. a
B. len
C. length
D. x
15. What value is printed when the following code is executed?
A. value
B. Second
C. parameter
D. First
E. Jane Doe
15.What will the following Python program print out? (Given that each word will actually print on
a new line)
def fred():
print("deri")
def jane():
print("Ethio Exams")
jane()
fred()
jane()
i=1
while True:
if i%2 == 0:
break
print(i)
i += 1
a. 1
b. 12
c. 123
d. None of these
19.Which keyword is used to take the control to the beginning of the loop?
a. exit
b. break
c. continue
d. None of these
20.The symbol that is placed at the end of if condition is
a. ;
b. :
c. &
d. ~
21.What is the keyword that is used to come out of a loop only for that iteration?
a. break
b. return
c. continue
d. if
22.Judge the output of the following code snippet. for i in range(10):
if i == 5:
break else:
print(i)
a. 0 1 2 3 4
b. 0 1 2 3 4 5
c. 0 1 2 3
d. 1 2 3 4 5
23.Predict the output of the following code snippet. while True:
print(True) break
a. True
b. False
c. None
d. Syntax error
24.The output of the below expression is
>>>10 * (1/0).
a. OverflowError
b. ZeroDivisionError
c. NameError
d. TypeError
25.How many except statements can a try-except block have?
a. Zero
b. One
c. More than one
d. More than zero
26.The syntax for renaming of a file is
a. rename(current_file_name, new_file_name)
b. rename(new_file_name, current_file_name,)
c. rename(()(current_file_name, new_file_name))
d. None of the above
27.The mode that is used to refer to binary data is
a. r
b. w
c. +
d. b
28.What is the output of the expression?
round(4.5676,2)?
A 4.5
B 4.6
C 4.57
D 4.56
29.What is the output of the functions shown below?
divmod(10.5,5)
divmod(2.4,1.2)
A 4.5
B 4.6
C 4.57
D 4.56
divmod(2.4,1.2)
Af
B 0xF
C 0Xf
D 0xf
d["john"]
A 40
B 45
C “john”
D “peter”
print(a.get(1,4))
A1
BA
C4
D Invalid syntax for get method
def insert(items):
if items in total:
total[items] += 1
else:
total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
A3
B1
C2
D0
a[2]=1
a[1]=[2,3,4]
print(a[1][1])
A [2,3,4].
B3
C2
D An exception is thrown
def func():
global x
print('x is', x)
x=2
func()
print('Value of x is', x)
A 432
B 24000
C 430
D No output
40.What is called when a function is defined inside a class?
A Module
B Class
C Another function
D Method
41.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))
A4
B5
C1
D An exception is thrown
42.i = 1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 3
b) error
c) 1 2
d) none of the mentioned
43.What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
44.Which of the following functions is a built-in function in python?
a) factorial()
b) print()
c) seed()
d) sqrt()
45.The following python program can work with ____ parameters.
def f(x):
def f1(*args, **kwargs):
print("Sanfoundry")
return x(*args, **kwargs)
return f1
a) any number of
b) 0
c) 1
d) 2
46.What will be the output of the following Python function?
min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False
47.What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i.upper())
a) a B C D
b) a b c d
c) error
d) A B C D
48.What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the built-in namespace, then the global namespace and finally the local
namespace
b) Python first searches the built-in namespace, then the local namespace and finally the global
namespace
c) Python first searches the local namespace, then the global namespace and finally the built-in
namespace
d) Python first searches the global namespace, then the local namespace and finally the built-in
namespace
49.What will be the output of the following Python code snippet?
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) error
b) 0 1 2 0
c) 0 1 2
d) none of the mentioned