CNIT 155 MIDTERM 2026 EXAM QUESTIONS AND
SOLUTIONS RATED A+
✔✔Which of the following statements about a programs main function is not true?
it must be called before it is defined
by convention, it is the first function to be called
all answers are not true
by convention, it is called after all functions are defined - ✔✔it must be called before it is
defined
✔✔What will be displayed when the following code is executed?
number = 6
while number > 0:
number -= 3
print(number, end = ' ')
630
30
0 -3
6 3 - ✔✔3 0
✔✔Which character starts a comment in a python program? - ✔✔#
✔✔What's the output?
count = 0
for n in range (6):
if n % 2 !=0:
count = count + 2
print(count) - ✔✔6
✔✔Which of the following is the correct syntax for a while loop?
while(condition)
Block of statements
while(condition):
Block of statements
while var in sequence:
statement
while(condition):
, Block of statements - ✔✔while(condition):
Block of statements
✔✔Analyze the following code.
count = 0
while count < 100:
# Point A
print("Welcome to Python!")
count += 1
# Point B
# Point C - ✔✔count < 100 is always True at Point A
✔✔Which of the following range function will result in a for loop counting backwards?
range(-1, 3)
range(3, 0, -1)
range(1, 3, -1)
range(3, -1) - ✔✔range(3, 0, -1)
✔✔The input function is used to ______ and returns a ________. - ✔✔prompt for text
input from user, string
✔✔Which of the following have the highest precedence?
=Assignment operator
Arithmetic operators
Logical operators
Relational operators - ✔✔Arithmetic operators
✔✔Which of the following range function syntax is incorrect?
range(1, 2.5, 4.5)
range(10, 4, -1)
range(0, 3)
range(1, 3, 1) - ✔✔range(1, 2.5, 4.5)
✔✔The input function takes a _________ as a parameter value and returns a(n)
______. - ✔✔string, string
✔✔How many times will the following code print "Welcome to Python"?
count = 0
SOLUTIONS RATED A+
✔✔Which of the following statements about a programs main function is not true?
it must be called before it is defined
by convention, it is the first function to be called
all answers are not true
by convention, it is called after all functions are defined - ✔✔it must be called before it is
defined
✔✔What will be displayed when the following code is executed?
number = 6
while number > 0:
number -= 3
print(number, end = ' ')
630
30
0 -3
6 3 - ✔✔3 0
✔✔Which character starts a comment in a python program? - ✔✔#
✔✔What's the output?
count = 0
for n in range (6):
if n % 2 !=0:
count = count + 2
print(count) - ✔✔6
✔✔Which of the following is the correct syntax for a while loop?
while(condition)
Block of statements
while(condition):
Block of statements
while var in sequence:
statement
while(condition):
, Block of statements - ✔✔while(condition):
Block of statements
✔✔Analyze the following code.
count = 0
while count < 100:
# Point A
print("Welcome to Python!")
count += 1
# Point B
# Point C - ✔✔count < 100 is always True at Point A
✔✔Which of the following range function will result in a for loop counting backwards?
range(-1, 3)
range(3, 0, -1)
range(1, 3, -1)
range(3, -1) - ✔✔range(3, 0, -1)
✔✔The input function is used to ______ and returns a ________. - ✔✔prompt for text
input from user, string
✔✔Which of the following have the highest precedence?
=Assignment operator
Arithmetic operators
Logical operators
Relational operators - ✔✔Arithmetic operators
✔✔Which of the following range function syntax is incorrect?
range(1, 2.5, 4.5)
range(10, 4, -1)
range(0, 3)
range(1, 3, 1) - ✔✔range(1, 2.5, 4.5)
✔✔The input function takes a _________ as a parameter value and returns a(n)
______. - ✔✔string, string
✔✔How many times will the following code print "Welcome to Python"?
count = 0