Introduction to Programming Using Python, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors from the Instructor's Resource Website.

Chapter 3 Mathematical Functions, Strings, and Objects


Section 3.2 Common Python Functions
3.1  What is max(3, 5, 1, 7, 4)?
A. 1
B. 3
C. 5
D. 7
E. 4

3.2  What is min(3, 5, 1, 7, 4)?
A. 1
B. 3
C. 5
D. 7
E. 4

3.3  What is round(3.52)?
A. 3.5
B. 3
C. 5
D. 4
E. 3.0

3.4  What is round(6.5)?
A. 4
B. 5
C. 6
D. 7
E. 8

3.5  What is round(7.5)?
A. 4
B. 5
C. 6
D. 7
E. 8

3.6  Is pow(a, b) the same as a ** b?
A. Yes
B. No

3.7  What is math.degrees(math.pi / 2)?
A. 0.0
B. 90.0
C. 45.0
D. 30.0

3.8  What is math.radians(30) * 6?
A. 0.0
B. 1.3434343
C. 3.141592653589793
D. 5.565656

3.9  What is math.sin(math.pi / 6)?
A. 1.0
B. 1.3434343
C. 3.141592653589793
D. 0.5

Section 3.3 Strings and Characters
3.10  Which of the following is the correct expression of character 4?
A. 4
B. "4"
C. '4'

3.11  In Python, a string literal is enclosed in __________.
A. parentheses
B. brackets
C. single-quotes
D. double-quotes
E. braces

3.12  What is chr(ord('B')))?
A. A
B. B
C. C
D. D

3.13  Suppose x is a char variable with a value 'b'. What will be displayed by the statement print(chr(ord(x) + 1))?
A. a
B. b
C. c
D. d

3.14  Which of the following statement prints smith\exam1\test.txt?
A. print("smith\exam1\test.txt")
B. print("smith\\exam1\\test.txt")
C. print("smith\"exam1\"test.txt")
D. print("smith"\exam1"\test.txt")

3.15  Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?
A. print(i)
B. print(str(i))
C. print(int(i))
D. print(chr(i))

3.16  The Unicode of 'a' is 97. What is the Unicode for 'c'?
A. 96
B. 97
C. 98
D. 99

3.17  Will print(chr(4)) display 4?
A. Yes
B. No

3.18  What will be displayed by print(ord('z') - ord('a'))?
A. 25
B. 26
C. a
D. z

3.19  The expression "Good " + 1 + 2 + 3 evaluates to ________.
A. Good123
B. Good6
C. Good 123
D. Illegal expression

3.20  What will be displayed by the following code?

print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = ' ')
A. ABCD
B. A, B, C, D
C. A B C D
D. A, B, C, D will be displayed on four lines

3.21  Which of the following statements is correct?
A. s = "Chapter " + 1
B. s = "Chapter " + str(1)

Section 3.5 Introduction to Objects and Methods
3.22  What is the type for object 5.6?
A. int
B. float
C. str

3.23  Which of the following statements are true?
A. Each object has a unique id.
B. Objects of the same type have the same id.
C. Objects of the same kind have the same type.
D. A variable that holds a value is actually a reference to an object for the value.

3.24  Suppose s = "Welcome", what is type(s)?
A. int
B. float
C. str
D. String

3.25  Suppose s is "Welcome", what is s.upper()?
A. welcome
B. WELCOME
C. Welcome

3.26  Suppose s is "\t\tWelcome\n", what is s.strip()?
A. \t\tWelcome\n
B. \t\tWelcome\n
C. \t\tWELCOME\n
D. welcome

Section 3.6 Formatting Numbers and Strings
3.27  The format function returns _______.
A. an int
B. a float
C. a str

3.28  To format a number x to 3 digits after the decimal point, use _______.
A. format(x, "5.3f")
B. format("5.3f", x)
C. format(x, "5.4f")
D. format("5.3f", x)

3.29  Suppose x is 345.3546, what is format(x, "10.3f")? (note b represents a blank space)
A. bb345.355
B. bbb345.355
C. bbbb345.355
D. bbb345.354
E. bbbb345.354

3.30  What will be displayed by the following code? ? (note ? represents a blank space)

  print(format("Welcome", "10s"), end = '#')
  print(format(111, "4d"), end = '#')
  print(format(924.656, "3.2f"))
A. ???Welcome#?111#924.66
B. Welcome#111#924.66
C. Welcome#111#.66
D. Welcome???#?111#924.66

3.31  What will be displayed by the following code? ? (note ? represents a blank space)

  print(format("Welcome", ">10s"), end = '#')
  print(format(111, "<4d"), end = '#')
  print(format(924.656, ">10.2f"))
A. ???Welcome#?111#924.66
B. ???Welcome#?111#????924.66
C. ???Welcome#111?#????924.66
D. Welcome???#111?#????924.66

3.32  Suppse number contains integer value 4, which of the following statement is correct?
A. print(format(number, "2d"), format(number ** 1.5, "4d"))
B. print(format(number, "2d"), format(number ** 1.5, "4.2d"))
C. print(format(number, "2d"), format(number ** 1.5, "4.2f"))
D. print(format(number, "2f"), format(number ** 1.5, "4.2f"))
E. print(format(number, "2.1f"), format(number ** 1.5, "4.2f"))

Section 3.7 Drawing Various Shapes
3.33  To set the pen size to 5 pixels, use _________.
A. turtle.setSize(5)
B. turtle.size(5)
C. turtle.pensize(5)
D. turtle.setPenSize(5)

3.34  To undo the last turtle action, use _________.
A. turtle.rollback()
B. turtle.redo()
C. turtle.undo()
D. turtle.remove()

3.35  To set a turtle drawing speed to 5, use _________.
A. turtle.speed(5)
B. turtle.setSpeed(5)
C. turtle.setspeed(5)
D. turtle.velocity(5)

3.36  To draw a circle of diameter 10 with filled color red, use _________.
A. turtle.circle(5, "red")
B. turtle.circle(10, "red")
C. turtle.dot(5, "red")
D. turtle.dot(10, "red")