2 Introduction To Programming Using Python
2 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.
A. input("Enter a string")
B. eval(input("Enter a string"))
C. enter("Enter a string")
D. eval(enter("Enter a string"))
Check Answer for Question 1
A. "1 + 3 * 2"
B. 7
C. 8
D. "1 + 6"
Check Answer for Question 2
2.3 If you enter 1 2 3 in three separate lines, when you run this program, what will be displayed?
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)
A. 1.0
B. 2.0
C. 3.0
D. 4.0
Check Answer for Question 3
2.4 _______ is the code in natural language mixed with some program code.
A. Python program
B. A Python statement
C. Pseudocode
D. A flowchart diagram
Check Answer for Question 4
2.5 If you enter 1 2 3 in one line, when you run this program, what will happen?
# Compute average
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 1/8
12/14/23, 12:52 AM Introduction to Programming Using Python
average = (number1 + number2 + number3) / 3
# Display result
print(average)
2.6 You can place the line continuation symbol __ at the end of a line to tell the interpreter that the
statement is continued on the next line.
A. /
B. \
C. #
D. *
E. &
Check Answer for Question 6
A. true
B. false
Check Answer for Question 7
2.8 An identifier can contain digits, but cannot start with a digit?
A. true
B. false
Check Answer for Question 8
A. $343
B. mile
C. 9X
D. 8+9
E. max_radius
Check Answer for Question 9
A. import
B. mile1
C. MILE
D. (red)
E. "red"
Check Answer for Question 10
# Compute average
average = (number1 + number2 + number3) / 3
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 2/8
12/14/23, 12:52 AM Introduction to Programming Using Python
# Display result
print(average)
A. 1.0
B. 2.0
C. 3.0
D. 4.0
Check Answer for Question 11
x = 1
x = 2 * x + 1
print(x)
A. 0
B. 1
C. 2
D. 3
E. 4
Check Answer for Question 12
x = 1
x = x + 2.5
print(x)
A. 1
B. 2
C. 3
D. 3.5
E. The statements are illegal
Check Answer for Question 13
x, y = 1, 2
x, y = y, x
print(x, y)
A. 1 1
B. 2 2
C. 1 2
D. 2 1
Check Answer for Question 14
2.15 To following code reads two number. Which of the following is the correct input for the code?
A. 1 2
B. "1 2"
C. 1, 2
D. 1, 2,
Check Answer for Question 15
A. 10
B. 11
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 3/8
12/14/23, 12:52 AM Introduction to Programming Using Python
C. 11.25
D. 12
Check Answer for Question 16
2.17 In the expression 45 / 4, the values on the left and right of the / symbol are called ____.
A. operators
B. operands
C. parameters
D. arguments
Check Answer for Question 17
A. 10
B. 11
C. 11.25
D. 12
Check Answer for Question 18
A. 1 / 2
B. 1.0 / 2
C. 1 // 2
D. 1.0 // 2
E. 1 / 2.0
Check Answer for Question 19
A. 2 % 1
B. 15 % 4
C. 25 % 5
D. 37 % 6
Check Answer for Question 20
2.21 25 % 1 is _____
A. 1
B. 2
C. 3
D. 4
E. 0
Check Answer for Question 21
2.22 24 % 5 is _____
A. 1
B. 2
C. 3
D. 4
E. 0
Check Answer for Question 22
A. 9
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 4/8
12/14/23, 12:52 AM Introduction to Programming Using Python
B. 8
C. 9.0
D. 8.0
Check Answer for Question 23
A. 9
B. 8
C. 9.0
D. 8.0
Check Answer for Question 24
A. 36
B. 18
C. 12
D. 81
Check Answer for Question 25
x = 1
y = x = x + 1
print("y is", y)
A. y is 0.
B. y is 1 because x is assigned to y first.
C. y is 2 because x + 1 is assigned to x and then x is assigned to y.
D. The program has a compile error since x is redeclared in the statement int y = x = x + 1.
Check Answer for Question 26
A. 0.25E-1
B. 2.5e-2
C. 0.0025E1
D. 0.00025E2
E. 0.0025E+1
Check Answer for Question 27
A. causes overflow
B. causes underflow
C. causes no error
D. cannot happen in Python
Check Answer for Question 28
A. 4
B. 6
C. 4.0
D. 6.0
Check Answer for Question 29
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 5/8
12/14/23, 12:52 AM Introduction to Programming Using Python
Section 2.10 Augmented Assignment Operators
2.30 What is the value of i printed?
j = i = 1
i += j + j * 5
print("What is i?", i)
A. 0
B. 1
C. 5
D. 6
E. 7
Check Answer for Question 30
x = 1
x *= x + 1
A. x is 1
B. x is 2
C. x is 3
D. x is 4
Check Answer for Question 31
x = 2
y = 1
x *= y + 1
A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.
Check Answer for Question 32
A. 1 + x = x
B. x += 1
C. x := 1
D. x = x + 1
E. x = 1 + x
Check Answer for Question 33
(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)
A. number += sum
B. number = sum + number
C. sum = Number + sum
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 6/8
12/14/23, 12:52 AM Introduction to Programming Using Python
D. sum += number
E. sum = sum + number
Check Answer for Question 35
A. 0
B. 1
C. 2
D. 3
E. 4
Check Answer for Question 36
A. 0
B. 1
C. 2
D. -1
E. -2
Check Answer for Question 37
x = 1
y = 2
x *= y + 1
A. x is 1
B. x is 2
C. x is 3
D. x is 4
Check Answer for Question 38
A. int(3.4)
B. int(3.9)
C. round(3.4)
D. round(3.9)
Check Answer for Question 39
A. int("034")
B. eval("034")
C. int("3.4")
D. eval("3.4")
Check Answer for Question 40
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 7/8
12/14/23, 12:52 AM Introduction to Programming Using Python
E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).
Check Answer for Question 41
https://liveexample-ppe.pearsoncmg.com/selftest/selftestpy?chapter=2 8/8