4 Introduction To Programming Using Python
4 Introduction To Programming Using Python
Many questions in this edition have been updated in the new edition. Please check with the
publisher on the newest edition.
This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource
Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.
Chapter 4 Selections
Check Answer for All Questions
A. <
B. <=
C. =<
D. <<
E. !=
Check Answer for Question 1
A. <>
B. !=
C. ==
D. =
Check Answer for Question 2
A. a Python keyword
B. a Boolean literal
C. same as value 1
D. same as value 0
Check Answer for Question 3
A. random.randint(0, 5)
B. random.randint(0, 6)
C. random.randrange(0, 5)
D. random.randrange(0, 6)
Check Answer for Question 4
A. 0
B. 1
C. 0 or 1
D. 2
Check Answer for Question 5
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 1/7
12/14/23, 10:13 PM Introduction to Programming Using Python
Sections 4.4-4.10
4.7 Which of the following code displays the area of a circle if the radius is positive.
x = 0
if x < 4:
x = x + 1
print("x is", x)
A. x is 0
B. x is 1
C. x is 2
D. x is 3
E. x is 4
Check Answer for Question 8
4.9 Suppose isPrime is a boolean variable, which of the following is the correct and best statement for
testing if isPrime is true.
A. if isPrime = True:
B. if isPrime == True:
C. if isPrime:
D. if not isPrime = False:
E. if not isPrime == False:
Check Answer for Question 9
even = False
if even = True:
print("It is even!")
even = False
if even:
print("It is even!")
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 2/7
12/14/23, 10:13 PM Introduction to Programming Using Python
4.12 Suppose x = 1, y = -1, and z = 1. What will be displayed by the following statement?
if x > 0:
if y > 0:
print("x > 0 and y > 0")
elif z > 0:
print("x < 0 and z > 0")
temperature = 50
A. too hot
B. too cold
C. just right
D. too hot too cold just right
Check Answer for Question 13
Code 1:
if number % 2 == 0:
even = True
else:
even = False
Code 2:
even = number % 2 == 0
4.15 Suppose income is 4001, what will be displayed by f the following code?
A. none
B. Income is greater than 3000
C. Income is greater than 3000 followed by Income is greater than 4000
D. Income is greater than 4000
E. Income is greater than 4000 followed by Income is greater than 3000
Check Answer for Question 15
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 3/7
12/14/23, 10:13 PM Introduction to Programming Using Python
4.16 Suppose you write the code to display "Cannot get a driver's license" if age is less than 16
and "Can get a driver's license" if age is greater than or equal to 16.
Which of the following code is correct?
I:
if age < 16:
print("Cannot get a driver's license")
if age >= 16:
print("Can get a driver's license")
II:
if age < 16:
print("Cannot get a driver's license")
else:
print("Can get a driver's license")
III:
if age < 16:
print("Cannot get a driver's license")
elif age >= 16:
print("Can get a driver's license")
IV:
if age < 16:
print("Cannot get a driver's license")
elif age == 16:
print("Can get a driver's license")
elif age > 16:
print("Can get a driver's license")
A. I and II
B. II and III
C. I, II, and III
D. III and IV
E. All correct
Check Answer for Question 16
4.17 Suppose you write the code to display "Cannot get a driver's license" if age is less than 16
and "Can get a driver's license" if age is greater than or equal to 16.
Which of the following code is the best?
I:
if age < 16:
print("Cannot get a driver's license")
if age >= 16:
print("Can get a driver?s license")
II:
if age < 16:
print("Cannot get a driver's license")
else:
print("Can get a driver's license")
III:
if age < 16:
print("Cannot get a driver's license")
elif age >= 16:
print("Can get a driver's license")
IV:
if age < 16:
print("Cannot get a driver's license")
elif age == 16:
print("Can get a driver's license")
elif age > 16:
print("Can get a driver's license")
A. I
B. II
C. III
D. IV
Check Answer for Question 17
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 4/7
12/14/23, 10:13 PM Introduction to Programming Using Python
4.18 The __________ function immediately terminates the program.
A. sys.terminate()
B. sys.halt()
C. sys.exit()
D. sys.stop()
Check Answer for Question 18
4.20 Which of the following is the correct expression that evaluates to True if the number x is between 1
and 100 or the number is negative?
21. To check whether a char variable ch is an uppercase letter, you write ___________.
A. not (x == 4)
B. x != 4
C. x == 5
D. x != 5
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 5/7
12/14/23, 10:13 PM Introduction to Programming Using Python
A. not (x == 4)
B. x != 4
C. x == 5
D. x != 5
Check Answer for Question 25
A. not (x == y)
B. x > y and x < y
C. x > y or x < y
D. x >= y or| x <= y
Check Answer for Question 26
ch = 'F'
if ch >= 'A' and ch <= 'Z':
print(ch)
A. F
B. f
C. nothing
D. F f
Check Answer for Question 27
x = 0
y = 10 if x > 0 else -10
A. -10
B. 0
C. 10
D. 20
E. Illegal expression
Check Answer for Question 28
4.29 Analyze the following code fragments that assign a boolean value to the variable even.
Code 1:
if number % 2 == 0:
even = True
else:
even = False
Code 2:
even = True if number % 2 == 0 else False
Code 3:
even = number % 2 == 0
A. Code 2 has a syntax error, because you cannot have True and False literals in the conditional
expression.
B. Code 3 has a syntax error, because you attempt to assign number to even.
C. All three are correct, but Code 1 is preferred.
D. All three are correct, but Code 2 is preferred.
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 6/7
12/14/23, 10:13 PM Introduction to Programming Using Python
isCorrect = False
print("Correct" if isCorrect else "Incorrect")
A. Correct
B. Incorrect
C. nothing
D. Correct Incorrect
Check Answer for Question 30
A. and, or, *, +
B. *, +, and, or
C. *, +, and, or
D. *, +, or, and
E. or, and, *, +
Check Answer for Question 31
A. *
B. +
C. %
D. and
E. =
Check Answer for Question 32
A. True
B. False
Check Answer for Question 33
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=4 7/7