[go: up one dir, main page]

0% found this document useful (0 votes)
615 views13 pages

Python - Final Exam by Ethio Exams

This document contains a practice exam for students preparing for an exam on computer science topics. It includes 30 multiple choice questions testing concepts like loops, functions, data types, and dictionaries in Python. It also provides the answers to check responses. The exam is intended to help students learn and practice concepts from high school level computer science to prepare for further study in college.

Uploaded by

HENOK GIRMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
615 views13 pages

Python - Final Exam by Ethio Exams

This document contains a practice exam for students preparing for an exam on computer science topics. It includes 30 multiple choice questions testing concepts like loops, functions, data types, and dictionaries in Python. It also provides the answers to check responses. The exam is intended to help students learn and practice concepts from high school level computer science to prepare for further study in college.

Uploaded by

HENOK GIRMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ቀሰም Academy ቻLu

This exam is prepared by Ethio Exams

የምታቀርብላችሁ - ቀሰም ACADEMY

ከHigh school እስከ Campus አብረናችሁ ነን

JOIN US ON TELEGRAM
@QesemAcademy

ከHigh school እስከ Campus አብረናችሁ ነን Page 1


ቀሰም Academy ቻLu

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

Q 5 - What command is used to insert 6 in a list ‘‘L’’ at 3rd position ?

A - L.insert(2,6)

ከHigh school እስከ Campus አብረናችሁ ነን Page 2


ቀሰም Academy ቻLu

B - L.insert(3,6)

C - L.add(3,6)

D - L.append(2,6)

Q 6 - Analyze the given below code?

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.

B - Program has an error because class A does not have a constructor.

C - Program will print ‘Hello’ if we change print(d) to print(self.d).

D - Syntax Error.

Q 7 - Discuss the outcome of the code?

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.

B - Func1 and Func2 are tail recursions.

C - Func2 is only tail recursion.

D - Neither Func2 nor Func1 is tail recursion.

ከHigh school እስከ Campus አብረናችሁ ነን Page 3


ቀሰም Academy ቻLu

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>

Q 9 - Select the valid code to bind a canvas with a key event p −

A - Canvas.entered(Enter, p)

B - Canvas.entered(''<Enter> '',p)

C - Canvas.bind(''<key> '',p)

D - Canvas.bind(key,p)

Q 10 - What will be the output of the following code?

minidict = { 'name': 'TutorialsPoint', 'name': 'website'}


print(minidict['name'])
A - TutorialsPoint

B - Website

C - ('TutorialsPoint' , 'website')

D - It will show an Error.

8. The expression that requires type conversion when evaluated is .


a. 4.7 * 6.3
b. 1.7 % 2
c. 3.4 + 4.6
d. 7.9 * 6.3
9. The operator that has the highest precedence is .
a. << and >>
b. **
c. +
d. %
10. The expression that results in an error is . a. int(‘10.8’)

ከHigh school እስከ Campus አብረናችሁ ነን Page 4


ቀሰም Academy ቻLu

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. The lyrics print like normal.


B. We get a TypeError.
C. We get a NameError.
D. The program compiles but nothing prints.
12 def pow(b, p):
y = b ** p
return y
def square(x):
a = pow(x, 2)
return a
n=5
result = square(n)
print(result)

A. 5
B. 10
C. 25
D. 32
E. 3125
13: Consider the following Python code. What does this code print?

def rem(a, b):


return a % b
print(rem(3,7))

A. 0
B. 3
C. 7
D. 1
14. Which of the following would NOT work as a variable name?
A. a

ከHigh school እስከ Campus አብረናችሁ ነን Page 5


ቀሰም Academy ቻLu

B. len
C. length
D. x
15. What value is printed when the following code is executed?

name = "Jane Doe" defmyFunction(parameter):


value = "First"
value = parameter
print (value)
myFunction("Second")

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()

A. deri Ethio Exams jane fred jane


B. deri Ethio Exams deri
C. Ethio Exams deri jane
D. Ethio Exams deri Ethio Exams
E. deri deri deri
16. What is the output when the following statement is executed? print(0xD + 0xE + 0xF)
a. Error
b. 0XD0XE0XF
c. 0X22
d. 42

17. What is the output of print (0.1 + 0.2 == 0.3)?


a. True
b. False
c. Error
d. Machine dependent
18.Predict the output of the following code.

ከHigh school እስከ Campus አብረናችሁ ነን Page 6


ቀሰም Academy ቻLu

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).

ከHigh school እስከ Campus አብረናችሁ ነን Page 7


ቀሰም Academy ቻLu

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 (2.00, 0.50) (2.00, 0.00)


B (2, 0.5) (2, 0)
C (2.0, 0.5) (2.0, 0.0)
D (2, 0.5) (2)

30. What is the output of the expression?


round(4.5676,2)?

A 4.5
B 4.6
C 4.57
D 4.56

ከHigh school እስከ Campus አብረናችሁ ነን Page 8


ቀሰም Academy ቻLu

31.What is the output of the functions shown below?


divmod(10.5,5)

divmod(2.4,1.2)

A (2.00, 0.50) (2.00, 0.00)


B (2, 0.5) (2, 0)
C (2.0, 0.5) (2.0, 0.0)
D (2, 0.5) (2)

Answer: (2.0, 0.5) (2.0, 0.0)


32. What is the output of the function shown below?
hex(15)

Af
B 0xF
C 0Xf
D 0xf

33. What is the output?


d = {"john":40, "peter":45}

d["john"]

A 40
B 45
C “john”
D “peter”

34. What is the output of the following piece of code?


a={1:"A",2:"B",3:"C"}

print(a.get(1,4))

A1
BA
C4
D Invalid syntax for get method

35. What is the output of the following snippet of code?


total={}

def insert(items):

ከHigh school እስከ Campus አብረናችሁ ነን Page 9


ቀሰም Academy ቻLu

if items in total:

total[items] += 1

else:

total[items] = 1

insert('Apple')

insert('Ball')

insert('Apple')

print (len(total))

A3
B1
C2
D0

36. What is the output of the following code?


a={}

a[2]=1

a[1]=[2,3,4]

print(a[1][1])

A [2,3,4].
B3
C2
D An exception is thrown

38. What is the output of the below program?


x = 50

def func():

global x

print('x is', x)

ከHigh school እስከ Campus አብረናችሁ ነን Page 10


ቀሰም Academy ቻLu

x=2

print('Changed global x to', x)

func()

print('Value of x is', x)

A x is 50 Changed global x to 2 Value of x is 50


B x is 50 Changed global x to 2 Value of x is 2
C x is 50 Changed global x to 50 Value of x is 50
D None of the mentioned
39.What is the output of below program?
ef f(x, y, z): return x + y + z

f(2, 30, 400)

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:

ከHigh school እስከ Campus አብረናችሁ ነን Page 11


ቀሰም Academy ቻLu

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:

ከHigh school እስከ Campus አብረናችሁ ነን Page 12


ቀሰም Academy ቻLu

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?

for i in [1, 2, 3, 4][::-1]:


print (i)
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
50.What will be the output of the following Python program?

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

ከHigh school እስከ Campus አብረናችሁ ነን Page 13

You might also like