Sample Exam Questions
Final Exam – Part 1 (MCQ)
CPIT 110 (Problem-Solving and Programming)
Version 1.2
‫تنبيه‬
!
2
•
‫عألس‬ ‫ذ‬‫ذ‬‫ب‬ ‫ذعباألس‬‫ذ‬‫ل‬ ‫ذاأل‬‫ذ‬‫ي‬‫ذاألختب‬‫ذ‬‫ل‬‫ألتئ‬ ‫ذ‬‫ذ‬‫ي‬‫ذاألر‬‫ذ‬‫ن‬‫ذقألةي‬‫ذ‬‫ة‬‫عيأل‬ ‫ذ‬‫ذ‬‫ب‬‫ذعباألة‬‫ذ‬‫ل‬‫األسئ‬ ‫ذ‬‫ذ‬‫ه‬
‫أل‬ ‫ذ‬‫ذ‬‫ه‬‫ن‬
-
‫أل‬ ‫ن‬ ‫ث‬ ‫جزءألس‬ ‫س‬
(
‫عست‬ ‫ي‬ ‫س‬
‫)أل‬
‫مشكالتأل‬ ‫برمجاألوحلألس‬ ‫ميرعألس‬
(
CPIT-110
.)
•
‫كري‬‫س‬ ‫بم‬ ‫أل‬ ‫مدألةبيه‬ ‫ع‬ُ‫ب‬‫أل‬ ‫األسئلعباأل‬ ‫ه‬
.
•
‫ع‬ ‫ب‬ ‫ال‬ ‫ميرعيأل‬ ‫مئسليعألس‬ ‫األسئلعباألجميعألس‬ ‫ألتشملأله‬ ‫قدأل‬
.
•
‫ألس‬ ‫ذ‬‫ي‬‫كريألوتقب‬‫س‬ ‫ذ‬‫م‬‫ذقأل‬‫م‬‫ءأل‬ ‫ذ‬‫ه‬ ‫ن‬ ‫بمرسجعاألبعدألس‬ ‫لباأل‬ ‫األسئلعباألمن‬ ‫ه‬
‫ذيعأل‬‫ل‬‫مئس‬
‫ع‬ ‫ب‬ ‫ال‬ ‫ميرعيأل‬ ‫س‬
.
•
‫مبف‬ ‫سألس‬ ‫تأله‬ ‫باألصفح‬ ‫حبئلألسئلعباألمررياألنه‬
.
‫تنبيه‬
!
3
•
‫ألمقأل‬ً ‫بي‬ ‫هألل‬ ‫ألتمألدعسل‬ ‫ملألجميعألم‬ ‫عألش‬ ‫ب‬ ‫س‬
Chapter 1
‫ىأل‬‫ل‬‫إ‬
Chapter 6
.
•
‫ه‬ ‫ذ‬‫ذ‬‫م‬‫ذعألن‬‫ذ‬‫ي‬‫ذاألجم‬‫ذ‬‫ع‬‫ذئألمرسج‬‫ذ‬‫ج‬‫ألونر‬ ‫ذ‬‫ذ‬‫ي‬‫ألر‬ ‫د‬ ‫ذ‬‫ذ‬‫و‬ ‫قألس‬ ‫ذ‬‫ذ‬‫ب‬ ‫ذعباألس‬‫ذ‬‫ل‬ ‫ذهأل‬‫ذ‬‫ب‬‫أل‬ ‫ذئه‬‫ذ‬‫م‬‫ن‬ ‫سألس‬ ‫ذ‬‫ذ‬‫ه‬
‫أل‬
‫بيا‬ ‫و‬ ‫ألبئسقألس‬ ‫بياأل‬ ‫و‬ ‫عستألس‬ ‫ب‬ ‫س‬
‫أل‬.
Chapter 1, 2, 3:
Sample Exam Questions
Mid-Term Exam 1 – Part 1 (MCQ)
Chapter 4, 5:
Sample Exam Questions
Mid-Term Exam 2 – Part 1 (MCQ)
https://csu.kau.edu.sa/Pages-cpit110-test-questions.aspx
4
Chapter 6: Functions
Questions
5
Question
#1
6
If a function does not return a value, by default, it returns
___________.
a) None
b) Integer
c) Float
d) String
Section 6.2 Defining a Function
Question
#2
7
The header of a function consists of ____________.
a) function name
b) function name and parameter list
c) parameter list
d) return statement
Section 6.2 Defining a Function
Question
#3
8
A function _________.
a) must have at least one parameter
b) may have no parameters
c) must always have a return statement to return
a value
d) must always have a return statement to return
multiple values
Section 6.2 Defining a Function
Question
#4
9
Arguments to functions always appear within __________.
a) brackets
b) parentheses
c) curly braces
d) quotation marks
Section 6.3 Calling a Function
Question
#5
10
Does the function call in the following function cause syntax
errors?
import math
def main():
math.sin(math.pi)
main()
a) Yes
b) No
Section 6.3 Calling a Function
Question
#6
11
Each time a function is invoked, the system stores parameters
and local variables in an area of memory, known as _______,
which stores elements in last-in first-out fashion.
a) a heap
b) storage area
c) a stack
d) an array
Section 6.3 Calling a Function
Question
#7
12
Which of the following should be defined as a None function?
a) Write a function that prints integers from 1
to 100.
b) Write a function that returns a random
integer from 1 to 100.
c) Write a function that checks whether a number
is from 1 to 100.
d) Write a function that converts an uppercase
letter to lowercase.
Section 6.4 Functions With/Without Return Values
Question
#8
13
A function with no return statement returns ______.
a) void
b) 1
c) 0
d) None
Section 6.4 Functions With/Without Return Values
Question
#9
14
Consider the following incomplete code:
def f(number):
# Missing function body
print(f(5))
The missing function body should be ________.
a) return "number"
b) print(number)
c) print("number")
d) return number
Section 6.4 Functions With/Without Return Values
Question
#10
15
Given the following function header:
def f(p1, p2, p3, p4)
Which of the following is correct to invoke it?
a) f(1, 2, 3, 4)
b) f(p1 = 1, 2, 3, 4)
c) f(p1 = 1, p2 = 2, p3 = 3, 4)
d) f(p1 = 1, p2 = 2, p3 = 3, p2 = 4)
Section 6.5 Positional and Keyword Arguments
Question
#11
16
Given the following function header:
def f(p1, p2, p3, p4)
Which of the following is correct to invoke it?
a) f(1, 2, 3)
b) f(p1 = 1, 2, 3, 4)
c) f(p1 = 1, p2 = 2, p3 = 3, 4)
d) f(p1 = 1, p2 = 2, p3 = 3, p4 = 4)
Section 6.5 Positional and Keyword Arguments
Question
#12
17
Given the following function header:
def f(p1, p2, p3, p4)
Which of the following is correct to invoke it?
a) f()
b) f(p1 = 1, 2, 3, 4)
c) f(p1 = 1, p2 = 2, p3 = 3, 4)
d) f(1, 2, 3, p4 = 4)
Section 6.5 Positional and Keyword Arguments
Question
#13
18
Given the following function:
def nPrint(message, n):
while n > 0:
print(message, end="")
n -= 1
What will be displayed by the call nPrint('a', 4)?
a) aaaaa
b) aaaa
c) aaa
d) invalid call
e) infinite loop
Section 6.5 Positional and Keyword Arguments
Question
#14
19
Given the following function:
def nPrint(message, n):
while n > 0:
print(message)
n -= 1
What will be displayed by the call nPrint('a', 4)?
a) aaaaa
b) aaaa
c) aaa
d) invalid call
e) infinite loop
Section 6.5 Positional and Keyword Arguments
Question
#15
20
Given the following function:
def nPrint(message, n):
while n > 0:
print(message)
n -= 1
What is k after invoking nPrint("A message", k)?
k = 2
nPrint("A message", k)
a) 0
b) 1
c) 2
d) 3
Section 6.5 Positional and Keyword Arguments
Question
#16
21
Given the following function:
def nPrint(message, n):
while n > 0:
print(message)
n -= 1
What is k after invoking nPrint("A message", k)?
k = 2
nPrint(n = k, message = "A message")
a) 0
b) 1
c) 2
d) 3
Section 6.5 Positional and Keyword Arguments
Question
#17
22
A variable defined inside a function is referred to as __________.
a) a global variable
b) a function variable
c) a block variable
d) a local variable
Section 6.9 The Scope of Variables
Question
#18
23
A variable defined outside a function is referred to as
__________.
a) a global variable
b) a function variable
c) a block variable
d) a local variable
Section 6.9 The Scope of Variables
Question
#19
24
Whenever possible, you should avoid using __________.
a) global variables
b) function parameters
c) global constants
d) local variables
Section 6.9 The Scope of Variables
Question
#20
25
What will be displayed by the following code?
x = 1
def f1():
y = x + 2
print(y, end=" ")
f1()
print(x)
a) 1 3
b) 3 1
c) The program has a runtime error because x is not
defined.
d) 1 1
e) 3 3
Section 6.9 The Scope of Variables
Question
#21
26
What will be displayed by the following code?
x = 1
def f1():
x = 3
print(x, end=" ")
f1()
print(x)
a) 1 3
b) 3 1
c) The program has a runtime error because x is not
defined.
d) 1 1
e) 3 3
Section 6.9 The Scope of Variables
Question
#22
27
What will be displayed by the following code?
x = 1
def f1():
x = x + 2
print(x, end=" ")
f1()
print(x)
a) 1 3
b) 3 1
c) The program has a runtime error because x is not
defined.
d) 1 1
e) 3 3
Section 6.9 The Scope of Variables
Question
#23
28
What will be displayed by the following code?
x = 1
def f1():
global x
x = x + 2
print(x, end=" ")
f1()
print(x)
a) 1 3
b) 3 1
c) The program has a runtime error because x is not
defined.
d) 1 1
e) 3 3
Section 6.9 The Scope of Variables
Question
#24
29
What will be displayed by the following code?
def f1(x = 1, y = 2):
x = x + y
y += 1
print(x, y)
f1()
a) 1 3
b) 3 1
c) The program has a runtime error because x and y
are not defined.
d) 1 1
e) 3 3
Section 6.10 Default Arguments
Question
#25
30
What will be displayed by the following code?
def f1(x = 1, y = 2):
x = x + y
y += 1
print(x, y)
f1(2, 1)
a) 1 3
b) 2 3
c) The program has a runtime error because x and y
are not defined.
d) 3 2
e) 3 3
Section 6.10 Default Arguments
Question
#26
31
What will be displayed by the following code?
def f1(x = 1, y = 2):
x = x + y
y += 1
print(x, y)
f1(y = 2, x = 1)
a) 1 3
b) 2 3
c) The program has a runtime error because x and y
are not defined.
d) 3 2
e) 3 3
Section 6.10 Default Arguments
Question
#27
32
Which of the following function headers is correct?
a) def f(a = 1, b):
b) def f(a = 1, b, c = 2):
c) def f(a = 1, b = 1, c = 2):
d) def f(a = 1, b = 1, c = 2, d):
Section 6.10 Default Arguments
Question
#28
33
What will be displayed by the following code?
def hello():
print("Hello")
def hello(name = "Ahmad"):
print("Hi", name)
hello()
a) Hello
b) Hi
c) Hi Ahmad
d) Hello Ahmad
Section 6.10 Default Arguments
Question
#29
34
What will be displayed by the following code?
def hello():
print("Hello")
def hello(name = "Ahmad", age):
print("Name:", name, ", Age:", age)
hello(24)
a) Name: Ahmad, Age: 24
b) Name: None, Age: 24
c) Name: , Age: 24
d) Syntax Error
Section 6.10 Default Arguments
Question
#30
35
What will be displayed by the following code?
def f1(x = 1, y = 2):
return x + y, x - y
x, y = f1(y = 2, x = 1)
print(x, y)
a) 1 3
b) 3 1
c) The program has a runtime error because the
function returns the multiple values
d) 3 -1
e) -1 3
Section 6.11 Returning Multiple Values
Solutions
36
Question # Correct Answer
1 A
2 B
3 B
4 B
5 B
6 C
7 A
8 D
9 D
10 A
Question # Correct Answer
11 D
12 D
13 B
14 E
15 C
16 C
17 D
18 A
19 A
20 B
Solutions
37
Question # Correct Answer
21 B
22 C
23 E
24 E
25 D
26 E
27 C
28 C
29 D
30 D

Sample Exam Questions on Python for revision

  • 1.
    Sample Exam Questions FinalExam – Part 1 (MCQ) CPIT 110 (Problem-Solving and Programming) Version 1.2
  • 2.
    ‫تنبيه‬ ! 2 • ‫عألس‬ ‫ذ‬‫ذ‬‫ب‬ ‫ذعباألس‬‫ذ‬‫ل‬‫ذاأل‬‫ذ‬‫ي‬‫ذاألختب‬‫ذ‬‫ل‬‫ألتئ‬ ‫ذ‬‫ذ‬‫ي‬‫ذاألر‬‫ذ‬‫ن‬‫ذقألةي‬‫ذ‬‫ة‬‫عيأل‬ ‫ذ‬‫ذ‬‫ب‬‫ذعباألة‬‫ذ‬‫ل‬‫األسئ‬ ‫ذ‬‫ذ‬‫ه‬ ‫أل‬ ‫ذ‬‫ذ‬‫ه‬‫ن‬ - ‫أل‬ ‫ن‬ ‫ث‬ ‫جزءألس‬ ‫س‬ ( ‫عست‬ ‫ي‬ ‫س‬ ‫)أل‬ ‫مشكالتأل‬ ‫برمجاألوحلألس‬ ‫ميرعألس‬ ( CPIT-110 .) • ‫كري‬‫س‬ ‫بم‬ ‫أل‬ ‫مدألةبيه‬ ‫ع‬ُ‫ب‬‫أل‬ ‫األسئلعباأل‬ ‫ه‬ . • ‫ع‬ ‫ب‬ ‫ال‬ ‫ميرعيأل‬ ‫مئسليعألس‬ ‫األسئلعباألجميعألس‬ ‫ألتشملأله‬ ‫قدأل‬ . • ‫ألس‬ ‫ذ‬‫ي‬‫كريألوتقب‬‫س‬ ‫ذ‬‫م‬‫ذقأل‬‫م‬‫ءأل‬ ‫ذ‬‫ه‬ ‫ن‬ ‫بمرسجعاألبعدألس‬ ‫لباأل‬ ‫األسئلعباألمن‬ ‫ه‬ ‫ذيعأل‬‫ل‬‫مئس‬ ‫ع‬ ‫ب‬ ‫ال‬ ‫ميرعيأل‬ ‫س‬ . • ‫مبف‬ ‫سألس‬ ‫تأله‬ ‫باألصفح‬ ‫حبئلألسئلعباألمررياألنه‬ .
  • 3.
    ‫تنبيه‬ ! 3 • ‫ألمقأل‬ً ‫بي‬ ‫هألل‬‫ألتمألدعسل‬ ‫ملألجميعألم‬ ‫عألش‬ ‫ب‬ ‫س‬ Chapter 1 ‫ىأل‬‫ل‬‫إ‬ Chapter 6 . • ‫ه‬ ‫ذ‬‫ذ‬‫م‬‫ذعألن‬‫ذ‬‫ي‬‫ذاألجم‬‫ذ‬‫ع‬‫ذئألمرسج‬‫ذ‬‫ج‬‫ألونر‬ ‫ذ‬‫ذ‬‫ي‬‫ألر‬ ‫د‬ ‫ذ‬‫ذ‬‫و‬ ‫قألس‬ ‫ذ‬‫ذ‬‫ب‬ ‫ذعباألس‬‫ذ‬‫ل‬ ‫ذهأل‬‫ذ‬‫ب‬‫أل‬ ‫ذئه‬‫ذ‬‫م‬‫ن‬ ‫سألس‬ ‫ذ‬‫ذ‬‫ه‬ ‫أل‬ ‫بيا‬ ‫و‬ ‫ألبئسقألس‬ ‫بياأل‬ ‫و‬ ‫عستألس‬ ‫ب‬ ‫س‬ ‫أل‬.
  • 4.
    Chapter 1, 2,3: Sample Exam Questions Mid-Term Exam 1 – Part 1 (MCQ) Chapter 4, 5: Sample Exam Questions Mid-Term Exam 2 – Part 1 (MCQ) https://csu.kau.edu.sa/Pages-cpit110-test-questions.aspx 4
  • 5.
  • 6.
    Question #1 6 If a functiondoes not return a value, by default, it returns ___________. a) None b) Integer c) Float d) String Section 6.2 Defining a Function
  • 7.
    Question #2 7 The header ofa function consists of ____________. a) function name b) function name and parameter list c) parameter list d) return statement Section 6.2 Defining a Function
  • 8.
    Question #3 8 A function _________. a)must have at least one parameter b) may have no parameters c) must always have a return statement to return a value d) must always have a return statement to return multiple values Section 6.2 Defining a Function
  • 9.
    Question #4 9 Arguments to functionsalways appear within __________. a) brackets b) parentheses c) curly braces d) quotation marks Section 6.3 Calling a Function
  • 10.
    Question #5 10 Does the functioncall in the following function cause syntax errors? import math def main(): math.sin(math.pi) main() a) Yes b) No Section 6.3 Calling a Function
  • 11.
    Question #6 11 Each time afunction is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion. a) a heap b) storage area c) a stack d) an array Section 6.3 Calling a Function
  • 12.
    Question #7 12 Which of thefollowing should be defined as a None function? a) Write a function that prints integers from 1 to 100. b) Write a function that returns a random integer from 1 to 100. c) Write a function that checks whether a number is from 1 to 100. d) Write a function that converts an uppercase letter to lowercase. Section 6.4 Functions With/Without Return Values
  • 13.
    Question #8 13 A function withno return statement returns ______. a) void b) 1 c) 0 d) None Section 6.4 Functions With/Without Return Values
  • 14.
    Question #9 14 Consider the followingincomplete code: def f(number): # Missing function body print(f(5)) The missing function body should be ________. a) return "number" b) print(number) c) print("number") d) return number Section 6.4 Functions With/Without Return Values
  • 15.
    Question #10 15 Given the followingfunction header: def f(p1, p2, p3, p4) Which of the following is correct to invoke it? a) f(1, 2, 3, 4) b) f(p1 = 1, 2, 3, 4) c) f(p1 = 1, p2 = 2, p3 = 3, 4) d) f(p1 = 1, p2 = 2, p3 = 3, p2 = 4) Section 6.5 Positional and Keyword Arguments
  • 16.
    Question #11 16 Given the followingfunction header: def f(p1, p2, p3, p4) Which of the following is correct to invoke it? a) f(1, 2, 3) b) f(p1 = 1, 2, 3, 4) c) f(p1 = 1, p2 = 2, p3 = 3, 4) d) f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) Section 6.5 Positional and Keyword Arguments
  • 17.
    Question #12 17 Given the followingfunction header: def f(p1, p2, p3, p4) Which of the following is correct to invoke it? a) f() b) f(p1 = 1, 2, 3, 4) c) f(p1 = 1, p2 = 2, p3 = 3, 4) d) f(1, 2, 3, p4 = 4) Section 6.5 Positional and Keyword Arguments
  • 18.
    Question #13 18 Given the followingfunction: def nPrint(message, n): while n > 0: print(message, end="") n -= 1 What will be displayed by the call nPrint('a', 4)? a) aaaaa b) aaaa c) aaa d) invalid call e) infinite loop Section 6.5 Positional and Keyword Arguments
  • 19.
    Question #14 19 Given the followingfunction: def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? a) aaaaa b) aaaa c) aaa d) invalid call e) infinite loop Section 6.5 Positional and Keyword Arguments
  • 20.
    Question #15 20 Given the followingfunction: def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint("A message", k) a) 0 b) 1 c) 2 d) 3 Section 6.5 Positional and Keyword Arguments
  • 21.
    Question #16 21 Given the followingfunction: def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint(n = k, message = "A message") a) 0 b) 1 c) 2 d) 3 Section 6.5 Positional and Keyword Arguments
  • 22.
    Question #17 22 A variable definedinside a function is referred to as __________. a) a global variable b) a function variable c) a block variable d) a local variable Section 6.9 The Scope of Variables
  • 23.
    Question #18 23 A variable definedoutside a function is referred to as __________. a) a global variable b) a function variable c) a block variable d) a local variable Section 6.9 The Scope of Variables
  • 24.
    Question #19 24 Whenever possible, youshould avoid using __________. a) global variables b) function parameters c) global constants d) local variables Section 6.9 The Scope of Variables
  • 25.
    Question #20 25 What will bedisplayed by the following code? x = 1 def f1(): y = x + 2 print(y, end=" ") f1() print(x) a) 1 3 b) 3 1 c) The program has a runtime error because x is not defined. d) 1 1 e) 3 3 Section 6.9 The Scope of Variables
  • 26.
    Question #21 26 What will bedisplayed by the following code? x = 1 def f1(): x = 3 print(x, end=" ") f1() print(x) a) 1 3 b) 3 1 c) The program has a runtime error because x is not defined. d) 1 1 e) 3 3 Section 6.9 The Scope of Variables
  • 27.
    Question #22 27 What will bedisplayed by the following code? x = 1 def f1(): x = x + 2 print(x, end=" ") f1() print(x) a) 1 3 b) 3 1 c) The program has a runtime error because x is not defined. d) 1 1 e) 3 3 Section 6.9 The Scope of Variables
  • 28.
    Question #23 28 What will bedisplayed by the following code? x = 1 def f1(): global x x = x + 2 print(x, end=" ") f1() print(x) a) 1 3 b) 3 1 c) The program has a runtime error because x is not defined. d) 1 1 e) 3 3 Section 6.9 The Scope of Variables
  • 29.
    Question #24 29 What will bedisplayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1() a) 1 3 b) 3 1 c) The program has a runtime error because x and y are not defined. d) 1 1 e) 3 3 Section 6.10 Default Arguments
  • 30.
    Question #25 30 What will bedisplayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(2, 1) a) 1 3 b) 2 3 c) The program has a runtime error because x and y are not defined. d) 3 2 e) 3 3 Section 6.10 Default Arguments
  • 31.
    Question #26 31 What will bedisplayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(y = 2, x = 1) a) 1 3 b) 2 3 c) The program has a runtime error because x and y are not defined. d) 3 2 e) 3 3 Section 6.10 Default Arguments
  • 32.
    Question #27 32 Which of thefollowing function headers is correct? a) def f(a = 1, b): b) def f(a = 1, b, c = 2): c) def f(a = 1, b = 1, c = 2): d) def f(a = 1, b = 1, c = 2, d): Section 6.10 Default Arguments
  • 33.
    Question #28 33 What will bedisplayed by the following code? def hello(): print("Hello") def hello(name = "Ahmad"): print("Hi", name) hello() a) Hello b) Hi c) Hi Ahmad d) Hello Ahmad Section 6.10 Default Arguments
  • 34.
    Question #29 34 What will bedisplayed by the following code? def hello(): print("Hello") def hello(name = "Ahmad", age): print("Name:", name, ", Age:", age) hello(24) a) Name: Ahmad, Age: 24 b) Name: None, Age: 24 c) Name: , Age: 24 d) Syntax Error Section 6.10 Default Arguments
  • 35.
    Question #30 35 What will bedisplayed by the following code? def f1(x = 1, y = 2): return x + y, x - y x, y = f1(y = 2, x = 1) print(x, y) a) 1 3 b) 3 1 c) The program has a runtime error because the function returns the multiple values d) 3 -1 e) -1 3 Section 6.11 Returning Multiple Values
  • 36.
    Solutions 36 Question # CorrectAnswer 1 A 2 B 3 B 4 B 5 B 6 C 7 A 8 D 9 D 10 A Question # Correct Answer 11 D 12 D 13 B 14 E 15 C 16 C 17 D 18 A 19 A 20 B
  • 37.
    Solutions 37 Question # CorrectAnswer 21 B 22 C 23 E 24 E 25 D 26 E 27 C 28 C 29 D 30 D