Multiple Choices Questions PDF
Multiple Choices Questions PDF
Multiple Choices Questions PDF
A. Hardware
B. Software
C. Operating system
D. Application program
A. Hardware
B. CPU
C. Memory
D. Disk
A. megabytes
B. gigabytes
C. megahertz
D. gigahertz
A. because combinations of zeros and ones can represent any numbers and
characters.
D. because binary numbers are the bases upon which all other number
systems are built.
Your answer is correct
1.5 One byte has ________ bits.
A. 4
B. 8
C. 12
D. 16
A. 1 million
B. 10 million
C. 1 billion
D. 1 trillion
A. floppy disk
B. hard disk
C. flash stick
D. CD-ROM
E. memory
A. floppy disk
B. hard disk
C. flash stick
D. CD-ROM
A. Regular modem
B. DSL
C. Cable modem
D. NIC
A. Hardware
B. Software
C. Programs
D. Keyboards
A. machine language
B. assembly language
C. high-level language
A. An assembler
B. A compiler
C. CPU
B. C++
C. Windows XP
D. Visual Basic
E. Python
A. Operating system
B. Python
C. Modem
D. Interpreter
E. Compiler
A. James Gosling
B. Bill Gates
C. Steve Jobs
E. Google
A. Java
B. C++
C. C
D. C#
E. Python
A. Python
B. C++
C. C
D. Ada
E. Pascal
A. execute python
B. run python
C. python
D. go python
C. python t.py
D. go python t.py
Your answer is correct
1.21 Python syntax is case-sensitive.
A. True
B. False
A.
print("Programming is fun")
print("Python is fun")
B.
print("Programming is fun")
print("Python is fun")
C.
print("Programming is fun)
print("Python is fun")
D.
print("Programming is fun)
print("Python is fun")
A. A
B. B
C. C
D. D
A. //
B. /*
C. #
D. $$
B. /* comments */
D. /# comments #/
A. syntax
B. runtime
C. logic
B. interpreter/at runtime
C. compiler/at runtime
I:
print("Programming is fun")
print("Python")
print("Computer Science")
II:
print("Programming is fun")
print("Python")
print("Computer Science")
III:
print("Programming is fun")
print("Python")
print("Computer Science")
IV:
print("Programming is fun")
print("Python")
print("Computer Science")
A. I
B. II
C. III
D. IV
A. turtle.show()
B. turtle.showLocation()
C. turtle.showDirection()
D. turtle.showturtle()
E. turtle.showTurtle()
A. turtle.move(4, 5)
B. turtle.moveTo(4, 5)
C. turtle.moveto(4, 5)
D. turtle.go(4, 5)
E. turtle.goto(4, 5)
A. turtle.circle(50)
B. turtle.circle(100)
C. turtle.drawcircle(50)
D. turtle.drawCircle(50)
Your answer is correct
1.31 To lift the pen, use ___________.
A. turtle.penUp()
B. turtle.penup()
C. turtle.lift()
D. turtle.up()
A. turtle.penDown()
B. turtle.pendown()
C. turtle.putDown()
D. turtle.down()
A. input("Enter a string")
B. eval(input("Enter a string"))
C. enter("Enter a string")
D. eval(enter("Enter a string"))
A. "1 + 3 * 2"
B. 7
C. 8
D. "1 + 6"
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)
A. 1.0
B. 2.0
C. 3.0
D. 4.0
B. A Python statement
C. Pseudocode
D. A flowchart diagram
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)
A. /
B. \
C. #
D. *
E. &
B. false
A. true
B. false
A. $343
B. mile
C. 9X
D. 8+9
E. max_radius
A. import
B. mile1
C. MILE
D. (red)
E. "red"
# Compute average
average = (number1 + number2 + number3) / 3
# Display result
print(average)
A. 1.0
B. 2.0
C. 3.0
D. 4.0
x = 1
x = 2 * x + 1
print(x)
A. 0
B. 1
C. 2
D. 3
E. 4
x = 1
x = x + 2.5
print(x)
A. 1
B. 2
C. 3
D. 3.5
x, y = 1, 2
x, y = y, x
print(x, y)
A. 1 1
B. 2 2
C. 1 2
D. 2 1
A. 1 2
B. "1 2"
C. 1, 2
D. 1, 2,
A. 10
B. 11
C. 11.25
D. 12
A. operators
B. operands
C. parameters
D. arguments
A. 10
B. 11
C. 11.25
D. 12
A. 1 / 2
B. 1.0 / 2
C. 1 // 2
D. 1.0 // 2
E. 1 / 2.0
A. 2 % 1
B. 15 % 4
C. 25 % 5
D. 37 % 6
A. 1
B. 2
C. 3
D. 4
E. 0
A. 1
B. 2
C. 3
D. 4
E. 0
A. 9
B. 8
C. 9.0
D. 8.0
A. 9
B. 8
C. 9.0
D. 8.0
A. 36
B. 18
C. 12
D. 81
x = 1
y = x = x + 1
print("y is", y)
A. y is 0.
A. 0.25E-1
B. 2.5e-2
C. 0.0025E1
D. 0.00025E2
E. 0.0025E+1
A. causes overflow
B. causes underflow
C. causes no error
A. 4
B. 6
C. 4.0
D. 6.0
j = i = 1
i += j + j * 5
print("What is i?", i)
A. 0
B. 1
C. 5
D. 6
E. 7
x = 1
x *= x + 1
A. x is 1
B. x is 2
C. x is 3
D. x is 4
x = 2
y = 1
x *= y + 1
A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.
A. 1 + x = x
B. x += 1
C. x := 1
D. x = x + 1
E. x = 1 + x
Your answer is correct
2.34 Which of the following statements are the same?
(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)
A. number += sum
D. sum += number
A. 0
B. 1
C. 2
D. 3
E. 4
A. 0
B. 1
C. 2
D. -1
E. -2
x = 1
y = 2
x *= y + 1
A. x is 1
B. x is 2
C. x is 3
D. x is 4
A. int(3.4)
B. int(3.9)
C. round(3.4)
D. round(3.9)
A. int("034")
B. eval("034")
C. int("3.4")
D. eval("3.4")
A. 1
B. 3
C. 5
D. 7
E. 4
A. 1
B. 3
C. 5
D. 7
E. 4
A. 3.5
B. 3
C. 5
D. 4
E. 3.0
A. 4
B. 5
C. 6
D. 7
E. 8
A. 4
B. 5
C. 6
D. 7
E. 8
A. Yes
B. No
A. 0.0
B. 90.0
C. 45.0
D. 30.0
A. 0.0
B. 1.3434343
C. 3.141592653589793
D. 5.565656
B. 1.3434343
C. 3.141592653589793
D. 0.5
A. 4
B. "4"
C. '4'
A. parentheses
B. brackets
C. single-quotes
D. double-quotes
E. braces
A. A
B. B
C. C
D. D
A. a
B. b
C. c
D. d
A. print("smith\exam1\test.txt")
B. print("smith\\exam1\\test.txt")
C. print("smith\"exam1\"test.txt")
D. print("smith"\exam1"\test.txt")
A. print(i)
B. print(str(i))
C. print(int(i))
D. print(chr(i))
A. 96
B. 97
C. 98
D. 99
A. Yes
B. No
B. 26
C. a
D. z
A. Good123
B. Good6
C. Good 123
D. Illegal expression
A. ABCD
B. A, B, C, D
C. A B C D
A. s = "Chapter " + 1
A. int
B. float
C. str
A. int
B. float
C. str
D. String
A. welcome
B. WELCOME
C. Welcome
A. \t\tWelcome\n
B. \t\tWelcome\n
C. \t\tWELCOME\n
D. Welcome
A. an int
B. a float
C. a str
A. format(x, "5.3f")
B. format("5.3f", x)
C. format(x, "5.4f")
D. format("5.3f", x)
A. bb345.355
B. bbb345.355
C. bbbb345.355
D. bbb345.354
E. bbbb345.354
A. ???Welcome#?111#924.66
B. Welcome#111#924.66
C. Welcome#111#.66
D. Welcome???#?111#924.66
Your answer is correct
3.31 What will be displayed by the following code? ? (note ? represents a
blank space)
A. ???Welcome#?111#924.66
B. ???Welcome#?111#????924.66
C. ???Welcome#111?#????924.66
D. Welcome???#111?#????924.66
A. turtle.setSize(5)
B. turtle.size(5)
C. turtle.pensize(5)
D. turtle.setPenSize(5)
A. turtle.rollback()
B. turtle.redo()
C. turtle.undo()
D. turtle.remove()
A. turtle.speed(5)
B. turtle.setSpeed(5)
C. turtle.setspeed(5)
D. turtle.velocity(5)
A. turtle.circle(5, "red")
B. turtle.circle(10, "red")
C. turtle.dot(5, "red")
D. turtle.dot(10, "red")
A. <
B. <=
C. =<
D. <<
E. !=
A. <>
B. !=
C. ==
D. =
A. a Python keyword
B. a Boolean literal
C. same as value 1
D. same as value 0
A. random.randint(0, 5)
B. random.randint(0, 6)
C. random.randrange(0, 5)
D. random.randrange(0, 6)
Your answer is correct
4.5 random.randint(0, 1) returns ____________.
A. 0
B. 1
C. 0 or 1
D. 2
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
A. if isPrime = True:
B. if isPrime == True:
C. if isPrime:
even = False
if even = True:
print("It is even!")
even = False
if even:
print("It is even!")
C. The code is wrong. You should replace if even: with if even == True:
D. The code is wrong. You should replace if even: with if even = True:
Your answer is correct
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")
D. nothing displayed
temperature = 50
A. too hot
B. too cold
C. just right
Code 1:
if number % 2 == 0:
even = True
else:
even = False
Code 2:
even = number % 2 == 0
A. none
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
D. III and IV
E. All correct
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
A. sys.terminate()
B. sys.halt()
C. sys.exit()
D. sys.stop()
C. (x > 0) or (x < 0)
D. (x != 0) or (x = 0)
21. To check whether a char variable ch is an uppercase letter, you write ___
________.
D. x - 2 <= 4 or x - 2 >= -4
B. x - 2 >= 4 or x - 2 <= -4
D. x - 2 >= 4 or x - 2 <= -4
B. x < 5 or y < 5
D. x > 5 or y > 5
A. not (x == 4)
B. x != 4
C. x == 5
D. x != 5
A. not (x == 4)
B. x != 4
C. x == 5
D. x != 5
Your answer is correct
4.26 Which of the following is equivalent to x != y?
A. not (x == y)
C. x > y or x < y
ch = 'F'
if ch >= 'A' and ch <= 'Z':
print(ch)
A. F
B. f
C. nothing
D. F f
x = 0
y = 10 if x > 0 else -10
A. -10
B. 0
C. 10
D. 20
E. Illegal expression
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.
isCorrect = False
print("Correct" if isCorrect else "Incorrect")
A. Correct
B. Incorrect
C. nothing
D. Correct Incorrect
A. and, or, *, +
B. *, +, and, or
C. *, +, and, or
D. *, +, or, and
E. or, and, *, +
Your answer is correct
4.32 Which of the following operators are right-associative.
A. *
B. +
C. %
D. and
E. =
A. True
B. False
C. (x > 0 or x < 10 and y < 0) is same as (x > 0 or (x < 10 and y < 0))
D. (x > 0 or x < 10 and y < 0) is same as ((x > 0 or x < 10) and y < 0)
count = 0
while count < 10:
print("Welcome to Python")
count += 1
A. 8
B. 9
C. 10
D. 11
E. 0
x = 0
while 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
count = 0
while count < 100:
# Point A
print("Welcome to Python!")
count += 1
# Point B
# Point C
count = 0
while count < 10:
print("Welcome to Python")
A. 8
B. 9
C. 10
D. 11
number = 6
while number > 0:
number -= 3
print(number, end = ' ')
A. 6 3 0
B. 6 3
C. 3 0
D. 3 0 -3
E. 0 -3
sum = 0
for d in range(0, 10, 0.1):
sum += sum + d
A. The program has a syntax error because the range function cannot have
three arguments.
B. The program has a syntax error because the arguments in the range must
be integers.
A:
for count in range(1, 10):
print("Welcome to Python")
B:
for count in range(0, 10):
print("Welcome to Python")
C:
for count in range(1, 11):
print("Welcome to Python")
D:
for count in range(1, 12):
print("Welcome to Python")
A. BD
B. ABC
C. AC
D. BC
E. AB
A. 1, 2, 3, 4, 5
B. 0, 1, 2, 3, 4, 5
C. 1, 2, 3, 4
D. 0, 1, 2, 3, 4
A. range(0, 3)
B. range(0, 4)
C. range(3)
D. range(4)
A. range(0, 3.5)
B. range(10, 4, -1)
C. range(1, 3, 1)
D. range(2.5, 4.5)
A:
sum = 0
for i in range(1, 99):
sum += i / (i + 1)
B:
sum = 0
for i in range(1, 100):
sum += i / (i + 1)
C:
sum = 0
for i in range(1.0, 99.0):
sum += i / (i + 1)
D:
sum = 0
for i in range(1.0, 100.0):
sum += i / (i + 1)
print("Sum is", sum)
A. BCD
B. ABCD
C. B
D. CDE
E. CD
A. 1 2 3 4 5 6 7 8 9
B. 1 2 3 4 5 6 7 8 9 10
C. 1 2 3 4 5
D. 1 3 5 7 9
E. 2 4 6 8 10
y = 0
for i in range(0, 10):
y += i
print(y)
A. 10
B. 11
C. 12
D. 13
E. 45
y = 0
for i in range(0, 10, 2):
y += i
print(y)
A. 9
B. 10
C. 11
D. 20
y = 0
for i in range(10, 1, -2):
y += i
print(y)
A. 10
B. 40
C. 30
D. 20
A. Pattern A
B. Pattern B
C. Pattern C
D. Pattern D
sum = d = 0
while d != 10.0:
d += 0.1
sum += sum + d
A. The program does not run because sum and d are not initialized
correctly.
B. The program never stops because d is always 0.1 inside the loop.
A. add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose
initial value is 0.
B. add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable
whose initial value is 0.
for i in range(10):
for j in range(10):
print(i * j)
A. 100
B. 20
C. 10
D. 45
Your answer is correct
5.20 How many times is the print statement executed?
for i in range(10):
for j in range(i):
print(i * j)
A. 100
B. 20
C. 10
D. 45
balance = 10
while True:
if balance < 9: break
balance = balance - 9
A. Yes
B. No
sum = 0
item = 0
while item < 5:
item += 1
sum += item
if sum > 4: break
print(sum)
A. 5
B. 6
C. 7
D. 8
Your answer is correct
5.23 What is sum after the following loop terminates?
sum = 0
item = 0
while item < 5:
item += 1
sum += item
if sum >= 4: continue
print(sum)
A. 15
B. 16
C. 17
D. 18
balance = 10
while True:
if balance < 9: continue
balance = balance - 9
A. Yes
B. No
number = 25
isPrime = True
i = 2
while i < number and isPrime:
if number % i == 0:
isPrime = False
i += 1
A. i is 5 isPrime is True
B. i is 5 isPrime is False
C. i is 6 isPrime is True
D. i is 6 isPrime is False
number = 25
isPrime = True
for i in range(2, number):
if number % i == 0:
isPrime = False
break
A. i is 5 isPrime is True
B. i is 5 isPrime is False
C. i is 6 isPrime is True
D. i is 6 isPrime is False
A. 2*n
B. n
C. n - 1
D. n + 1
A. 2*n
B. n
C. n - 1
D. n + 1
isPrime = True
for i in range(2, number):
if number % i == 0:
isPrime = False
print("i is", i)
if isPrime:
print(number, "is prime")
break
else:
print(number, "is not prime")
A. i is 3 followed by 9 is prime
C. i is 2 followed by 9 is prime
A. None
B. int
C. double
D. public
E. null
A. function name
C. parameter list
A. brackets
B. parentheses
C. curly braces
D. quotation marks
import math
def main():
math.sin(math.pi)
main()
A. Yes
B. No
A. a heap
B. storage area
C. a stack
D. an array
A. void
B. nothing
C. 0
D. None
def f(number):
# Missing function body
print(f(5))
A. return "number"
B. print(number)
C. print("number")
D. return number
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, p4 = 4)
E. f(1, 2, 3, p4 = 4)
A. aaaaa
B. aaaa
C. aaa
D. invalid call
E. infinite loop
A. aaaaa
B. aaaa
C. aaa
D. invalid call
E. infinite loop
k = 2
nPrint("A message", k)
A. 0
B. 1
C. 2
D. 3
k = 2
nPrint(n = k, message = "A message")
A. 0
B. 1
C. 2
D. 3
A. function invocation
B. pass by value
C. pass by reference
D. pass by name
A. a global variable
B. a function variable
C. a block variable
D. a local variable
A. a global variable
B. a function variable
C. a block variable
D. a local variable
A. global variables
B. function parameters
C. global constants
D. local variables
x = 1
def f1():
y = x + 2
print(y)
f1()
print(x)
A. 1 3
B. 3 1
D. 1 1
E. 3 3
x = 1
def f1():
x = 3
print(x)
f1()
print(x)
A. 1 3
B. 3 1
D. 1 1
E. 3 3
Your answer is correct
6.21 What will be displayed by the following code?
x = 1
def f1():
x = x + 2
print(x)
f1()
print(x)
A. 1 3
B. 3 1
D. 1 1
E. 3 3
x = 1
def f1():
global x
x = x + 2
print(x)
f1()
print(x)
A. 1 3
B. 3 1
D. 1 1
E. 3 3
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
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
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
Your answer is correct
6.26 Which of the following function headers is correct?
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
A. Bottom-up approach
B. Top-down approach
D. Stepwise refinement
B. A function
A. A class
B. An object
C. A method
D. A data field
A. A class
B. An object
C. A method
D. A data field
A. program
B. class
C. method
D. data
A. def
B. return
C. class
A. A constructor
B. A class
C. A value-returning method
D. A None method
class A:
def __init__(self, s):
self.s = s
def print(self):
print(s)
a = A("Welcome")
a.print()
A. The program has an error because class A does not have a constructor.
B. The program has an error because class A should have a print method
with signature print(self, s).
C. The program has an error because class A should have a print method
with signature print(s).
class A:
def __init__(self, s):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()
A. The program has an error because class A does not have a constructor.
class A:
def __init__(self, s = "Welcome"):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()
A. The program has an error because class A does not have a constructor.
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.x)
C. The program has an error because you cannot name a variable using __y.
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.__y)
C. The program has an error because you cannot name a variable using __y.
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
a.x = 45
print(a.x)
C. The program has an error because you cannot name a variable using __y.
def A:
def __init__(self):
__a = 1
self.__b = 1
self.__c__ = 1
__d__ = 1
A. __a
B. __b
C. __c__
D. __d__
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
a.__y = 45
print(a.getX())
C. The program has an error because you cannot name a variable using __y.
def main():
myCount = Count()
times = 0
class Count:
def __init__(self):
self.count = 0
main()
A. 1
B. 2
C. 3
D. 4
E. -1
A. P
B. r
D. u
E. n
A. P
B. r
D. u
E. n
A. ram
B. ra
C. r
D. pr
E. pro
A. Pr
B. P
C. fun
D. n
E. un
A. P
B. r
C. Pr
D. ''
E. incorrect expression
A. Pr
B. P
C. fun
D. un
E. fu
A. Programming
B. rogramming is fun
C. Programming is f
D. Programming is fu
E. Programming is
A. Pr
B. P
C. Pro
D. Programming
E. Programming is
A. print(s[0])
B. print(s.lower())
C. s[1] = 'r'
D. print(s.strip())
class Count:
def __init__(self, count = 0):
self.__count = count
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))
A. True False
B. True True
C. False True
D. False False
A. 1
B. 2
C. 3
D. 4
A. 1
B. 2
C. 3
D. 4
E. -1
A. 1
B. 2
C. 3
D. 4
E. -1
A. 8
B. 7
C. 6
D. 5
E. -1
A. 8
B. 7
C. 6
D. 5
E. -1
A. 0
B. 1
C. -1
D. True
E. False
A. 0
B. 1
C. -1
D. True
E. False
A. 0
B. 1
C. -1
D. True
E. False
A. 0
B. 1
C. -1
D. True
E. False
A. God
B. Good
C. Geed
D. Ged
E. Good
class Name:
def __init__(self, firstName, mi, lastName):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
firstName = "John"
name = Name(firstName, 'F', "Smith")
firstName = "Peter"
name.lastName = "Pan"
print(name.firstName, name.lastName)
class MyDate:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
class Name:
def __init__(self, firstName, mi, lastName, birthDate):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
self.birthDate = birthDate
birthDate = MyDate(1990, 1, 1)
name = Name("John", 'F', "Smith", birthDate)
birthDate = MyDate(1991, 1, 1)
birthDate.year = 1992
print(name.birthDate.year)
A. s3 = s1 + s2
B. s3 = s1.add(s2)
C. s3 = s1.__add(s2)
D. s3 = s1.__add__(s2)
A. s[3]
B. s.getitem(3)
C. s.__getitem__(3)
D. s.getItem(3)
A. s.__len__()
B. len(s)
C. size(s)
D. s.size()
A. obj.__str__()
B. str(obj)
C. obj.str()
D. __str__(obj)
A. s1.__contains__(s2)
B. s1 in s2
C. s1.contains(s2)
D. si.in(s2)
A. i.__add(j)
B. i.__add__(j)
C. i.__Add(j)
D. i.__ADD(j)
Sections 9.2-9.4
9.1 How do you create a window?
A. window = newWindow()
B. window = Window()
C. window = Frame()
D. window = Tk()
A. frame = newWindow()
B. frame = Window()
C. frame = Frame()
D. frame = Tk()
A. window.loop()
B. window.main()
C. window.mainloop()
D. window.eventloop()
A. v1 = 5
B. v1.setValue(5)
C. v1.set(5)
D. v1.get(5)
A. use Label
B. Use Button
C. Use Text
D. Use Message
A. use Label
B. Use Button
C. Use Text
D. Use Message
Section 9.5
9.12 How do you create a canvas under parent frame1 with background color
white and foregroung color green?
Section 9.5
9.13 How do you draw a rectangle centered at 100, 100 with width 100 and
height 100 on canvas?
A. pack
B. grid
C. place
D. flow
A. pack manager
B. grid manager
C. place manager
D. flow manager
A. component.pack(LEFT)
B. component.pack(side = LEFT)
C. component.pack(side = "LEFT")
D. component.pack("LEFT")
A. LEFT
B. RIGHT
C. BOTTOM
D. TOP
A. row
B. column
C. rowspan
D. columnspan
A. image = PhotoImage(imagefilename)
D. image = PhotoImage(imagefilename)
Your answer is correct
9.25 You can create an image from a ____________ file.
A. .png
B. .gif
C. .bmp
D. .jpg
A. a label
B. a button
C. a check button
D. a radio button
E. an entry
A. menubar = Menu(window)
B. menubar = MenBar(window)
C. menubar = Menu()
D. menubar = MenBar()
A. menu1 = Menu(menubar)
B. menu1 = menu(menubar)
C. menu1 = Menu(winodw)
D. menu1 = Menu()
Your answer is correct
9.29 To add a menubar, use __________
A. window.configure(menu = menubar)
B. window.config(menubar)
C. window.config(menu = menubar)
D. window.configure(menubar)
Sections 9.10-9.11
9.30 To display a popup menu, use __________
A. menu.display()
B. menu.post()
C. menu.display(300, 300)
D. menu.post(300, 300)
A. canvas.left(p)
B. canvas.bind("<Button-1>", p)
C. canvas.bind("Button-1", p)
D. canvas.bind(<Button-1>, p)
A. canvas.left(p)
B. canvas.bind("<Button-1>", p)
C. canvas.bind("Button-1", p)
D. canvas.bind(<Button-1>, p)
E. canvas.bind("<Button-3>", p)
Your answer is correct
9.33 To bind a canvas with a mouse entered event p, use __________
A. canvas.entered(p)
B. canvas.bind("<Enter>", p)
C. canvas.bind("<Entered>", p)
D. canvas.bind(<Enter>, p)
A. <B1-Motion>
B. <B2-Motion>
C. <B3-Motion>
D. <Button-1>
E. <Button-2>
A. <ButtonReleased-1>
B. <ButtonReleased-2>
C. <ButtonReleased-3>
D. <ButtonPressed-1>
E. <ButtonPressed-2>
A. <Double-Button-1>
B. <Double-Button-2>
C. <Double-Button-3>
D. <Triple-Button-1>
E. <Triple-Button-2>
A. canvas.entered(p)
B. canvas.bind("<Enter>", p)
C. canvas.bind("<Key>", p)
D. canvas.bind(<Enter>, p)
E. canvas.bind("<Enter>", p)
A. x
B. y
C. widget
D. X
E. Y
A. list1 = list()
B. list1 = []
D. list1 = [12, 4, 4]
B. ['ab']
C. ['cd']
D. ['abcd']
A. 6
B. 7
C. 8
D. 5
E. 4
A. 5
B. 4
C. 8
D. 25
E. 1
Your answer is correct
10.5 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is min(list1)?
A. 5
B. 4
C. 8
D. 25
E. 1
A. 5
B. 4
C. 6
D. 2
E. 1
A. list1.shuffle()
B. shuffle(list1)
C. random.shuffle(list1)
D. random.shuffleList(list1)
A. print(list1[0])
B. print(list1[:2])
C. print(list1[:-2])
D. print(list1[4:6])
Your answer is correct
10.9 Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[-1]?
A. 3
B. 5
C. 1
D. 0
A. 0
B. [1, 3, 2, 4, 5, 2, 1]
C. [1, 3, 2, 4, 5, 2]
D. [1, 3, 2, 4, 5, 2, 1, 0]
A. [2, 6, 4]
B. [1, 3, 2, 1, 3]
C. [1, 3, 2, 1, 3, 2]
D. [1, 3, 2, 3, 2, 1]
A. [0, 1, 2, 3]
B. [0, 1, 2, 3, 4]
B. False
A. True
B. False
A. list1.add(5)
B. list1.append(5)
C. list1.addLast(5)
D. list1.addEnd(5)
A. list1.insert(3, 5)
B. list1.insert(2, 5)
C. list1.add(3, 5)
D. list1.append(3, 5)
A. list1.remove("red")
B. list1.remove(red)
C. list1.removeAll("red")
D. list1.removeOne("red")
B. 4
C. 1
D. 2
A. 0
B. 4
C. 1
D. 2
C. [25, 20, 5, 5, 4, 3, 3, 1]
C. [25, 20, 5, 5, 4, 3, 3, 1]
B. ['a b c d']
C. ['a#b#c#d']
D. ['abcd']
myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
print(indexOfMax)
A. 0
B. 1
C. 2
D. 3
E. 4
myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
myList[i - 1] = myList[i]
A. 2 3 4 5 6 1
B. 6 1 2 3 4 5
C. 2 3 4 5 6 6
D. 1 1 2 3 4 5
E. 2 3 4 5 6 1
Your answer is correct
list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
A. [1, 3]
B. [4, 3]
C. [1, 4]
D. [1, 3, 4]
Sections 10.7-10.8
10.30 What will be displayed by the following code?
def f(values):
values[0] = 44
v = [1, 2, 3]
f(v)
print(v)
A. [1, 44]
B. [1, 2, 3, 44]
C. [44, 2, 3]
D. [1, 2, 3]
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
A. 1 1
B. 1 44
C. 3 1
D. 3 44
f(1)
f(2)
v = f(3)
print(v)
C. [1, 2, 3]
D. 1 2 3
A. insertion point
B. insertion point - 1
C. -(insertion point + 1)
D. -insertion point
A. at index 3
B. at index 4
C. at index 5
D. at index 6
A. 1
B. 2
C. 4
D. 7
A. 0
B. 1
C. 2
D. 3
E. 4
A. 0
B. 1
C. 2
D. 3
E. 4
C. [1, 2, 3, 4, 5, 6, 7, 8, 9]
D. [0, 1, 2, 1, 2, 3, 2, 3, 4]
C. [1, 2, 3, 4, 5, 6, 7, 8, 9]
D. [0, 1, 2, 1, 2, 3, 2, 3, 4]
A. 8
B. 12
C. 16
D. 32
A. 2 and 1
B. 2 and 2
C. 3 and 2
D. 2 and 3
E. 3 and 3
A. 2, 3, and 3
B. 2, 3, and 4
C. 3, 3, and 3
D. 3, 3, and 4
E. 2, 2, and 2
v = values[0][0]
for row in range(0, len(values)):
for column in range(0, len(values[row])):
if v < values[row][column]:
v = values[row][column]
print(v)
A. 1
B. 3
C. 5
D. 6
E. 33
v = values[0][0]
for lst in values:
for element in lst:
if v > element:
v = element
print(v)
A. 1
B. 3
C. 5
D. 6
E. 33
A. 1 2 3 4
B. 4 5 6 7
C. 1 3 8 12
D. 2 5 9 13
E. 3 6 10 14
A. 1 2 3 4
B. 4 5 6 7
C. 1 3 8 12
D. 2 5 9 13
E. 3 6 10 14
def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
A. 3 33
B. 1 1
C. 5 6
D. 5 33
E. 33 5
print(data[1][0][0])
A. 1
B. 2
C. 4
D. 5
E. 6
def ttt(m):
v = m[0][0]
for row in m:
for element in row:
if v < element: v = element
return v
print(ttt(data[0]))
A. 1
B. 2
C. 4
D. 5
E. 6
class A:
def __init__(self, i = 0):
self.i = i
class B(A):
def __init__(self, j = 0):
self.j = j
def main():
b = B()
print(b.i)
print(b.j)
main()
C. When you create an object B, you have to pass an integer such as B(5).
class A:
def __init__(self, i = 1):
self.i = i
class B(A):
def __init__(self, j = 2):
super().__init__()
self.j = j
def main():
b = B()
print(b.i, b.j)
main()
A. 0 0
B. 0 1
C. 1 2
D. 0 2
E. 2 1
Your answer is correct
12.3 What is the output of the following code?
class ParentClass:
def __init__(self):
self.__x = 1
self.y = 10
def print(self):
print(self.__x, self.y)
class ChildClass(ParentClass):
def __init__(self):
super().__init__()
self.__x = 2
self.y = 20
c = ChildClass()
c.print()
A. 1 10
B. 1 20
C. 2 10
D. 2 20
A. super().__init__()
B. super().__init__(self)
C. B.__init__()
D. B.__init__(self)
class A:
def __init__(self, i = 1):
self.i = i
class B(A):
def __init__(self, j = 2):
___________________
self.j = j
def main():
b = B()
print(b.i, b.j)
main()
A. super().__init__(self)
B. super().__init__()
C. A.__init__()
D. A.__init__(self)
class A:
def __init__(self, i = 0):
self.i = i
def m1(self):
self.i += 1
class B(A):
def __init__(self, j = 0):
A.__init__(self, 3)
self.j = j
def m1(self):
self.j += 1
def main():
b = B()
b.m1()
print(b.i, b.j)
main()
A. 2 0
B. 3 1
C. 4 0
D. 3 0
E. 4 1
class A:
def __new__(self):
self.__init__(self)
print("A's __new__() invoked")
def __init__(self):
print("A's __init__() invoked")
class B(A):
def __new__(self):
print("B's __new__() invoked")
def __init__(self):
print("B's __init__() invoked")
def main():
b = B()
a = A()
main()
class A:
def __init__(self):
self.i = 1
def m(self):
self.i = 10
class B(A):
def m(self):
self.i += 1
return self.i
def main():
b = B()
print(b.m())
main()
A. 1
B. 2
C. 10
class A:
def __str__(self):
return "A"
class B(A):
def __str__(self):
return "B"
class C(B):
def __str__(self):
return "C"
def main():
b = B()
a = A()
c = C()
print(a, b, c)
main()
A. C C C
B. A B C
C. A A A
D. B B B
class A:
def __str__(self):
return "A"
class B(A):
def __init__(self):
super().__init__()
class C(B):
def __init__(self):
super().__init__()
def main():
b = B()
a = A()
c = C()
print(a, b, c)
main()
A. C C C
B. A B C
C. A A A
D. B B B
class A:
def __init__(self, i = 2, j = 3):
self.i = i
self.j = j
def __str__(self):
return "A"
def main():
x = A(1, 2)
y = A(2, 1)
print(x == y)
main()
A. True
B. False
C. 2
D. 1
class Person:
def getInfo(self):
return "Person's getInfo is called"
def printPerson(self):
print(self.getInfo(), end = ' ')
class Student(Person):
def getInfo(self):
return "Student's getInfo is called"
def main():
Person().printPerson()
Student().printPerson()
main()
class Person:
def __getInfo(self):
return "Person's getInfo is called"
def printPerson(self):
print(self.__getInfo(), end = ' ')
class Student(Person):
def __getInfo(self):
return "Student's getInfo is called"
def main():
Person().printPerson()
Student().printPerson()
main()
class A:
def __init__(self):
self.setI(20)
print("i from A is", self.i)
class B(A):
def __init__(self):
super().__init__()
b = B()
class A:
def __init__(self):
self.setI(20)
class B(A):
def __init__(self):
super().__init__()
print("i from B is", self.i)
b = B()
A. o.isinstance(A)
B. A.isinstance(o)
C. isinstance(o, A)
D. isinstance(A, o)
B. composition
C. inheritance
A. association
B. composition
C. inheritance
A. association
B. composition
C. inheritance
A. association
B. composition
C. inheritance
A. association
B. composition
C. inheritance
A. When you open a file for reading, if the file does not exist, an error
occurs.
B. When you open a file for writing, if the file does not exist, an error
occurs.
C. When you open a file for reading, if the file does not exist, the
program will open an empty file.
D. When you open a file for writing, if the file does not exist, a new
file is created.
E. When you open a file for writing, if the file exists, the existing
file is overwritten with the new file.
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Your answer is correct
13.9 The readlines() method returns a ____________.
A. str
B. a list of lines
D. a list of integers
A. os.path.isFile(f)
B. os.path.exists(f)
C. os.path.isfile(f)
D. os.isFile(f)
A. filename = askopenfilename()
B. filename = asksaveasfilename()
C. filename = openfilename()
D. filename = saveasfilename()
A. filename = askopenfilename()
B. filename = asksaveasfilename()
C. filename = openfilename()
D. filename = saveasfilename()
A. infile = urllib.request.urlopen(urlString)
B. infile = urllib.urlopen(urlString)
C. infile = request.urlopen(urlString)
D. infile = urlopen(urlString)
A. encode()
B. decode()
C. convert()
D. toString()
try:
list = 5 * [0]
x = list[5]
print("Done")
except IndexError:
print("Index out of bound")
C. "Done"
D. Nothing displayed
def main():
try:
f()
print("After the function call")
except ZeroDivisionError:
print("Divided by zero!")
except:
print("Exception")
def f():
print(1 / 0)
main()
C. "Divided by zero!"
try:
list = 10 * [0]
x = list[9]
print("Done")
except IndexError:
print("Index out of bound")
else:
print("Nothing is wrong")
finally:
print("Finally we are here")
try:
list = 10 * [0]
x = list[10]
print("Done")
except IndexError:
print("Index out of bound")
else:
print("Nothing is wrong")
finally:
print("Finally we are here")
A. "Done" followed by "Nothing is wrong"
A. write
B. output
C. dump
D. send
B. input
C. load
D. receive
A. print(t[3])
B. t[3] = 45
C. print(max(t))
D. print(len(t))
E. print(sum(t))
A. (1, 2)
B. (1, 2, 4)
C. (2, 4)
D. (2, 4, 3)
E. (1, 2, 4, 3)
A. (1, 2)
B. (1, 2, 4)
C. (2, 4)
D. (2, 4, 3)
E. (1, 2, 4, 3)
A. [2, 3, 9]
B. [1, 2, 4, 3, 8, 9]
C. [1, 4, 8]
D. (1, 4, 8)
E. (2, 3, 9)
A. (1, 2, 1, 2)
B. [1, 2, 1, 2]
C. (1, 1, 2, 2)
D. [1, 1, 2, 2]
E. illegal
A. True
B. False
A. list("abac")
B. tuple("abac")
C. set("abac")
D. None
A. { }
B. ( )
C. [ ]
D. set()
B. true ifthe elements in s1 are compared less than the elements in s2.
E. illegal
A. sum(s)
B. len(s)
C. min(s)
D. max(s)
E. None
A. print(s[3])
B. s[3] = 45
C. print(max(s))
D. print(len(s))
E. print(sum(s))
E. This method is executed fine and 4 is not added to the set since 4 is
already in the set.
Your answer is correct
14.13 Suppose s = {1, 2, 4, 3}, what happens when invoking s.remove(12)?
A. s1 == s2
B. s1 != s2
A. s1.issubset(s2)
B. s1.issuperset(s2)
C. s2.issubset(s1)
D. s2.issuperset(s1)
A. {1, 2, 4, 3, 1, 5, 4, 13}
B. {1, 2, 4, 3, 5, 13}
C. {1, 2, 4, 3}
D. {1, 5, 4, 13}
A. {2, 3, 5, 13}
B. {1, 2, 4, 3, 5, 13}
C. {1, 2, 4, 3}
D. {1, 5, 4, 13}
E. {2, 3}
A. {2, 3, 5, 13}
B. {1, 2, 4, 3, 5, 13}
C. {1, 4}
D. {1, 5, 4, 13}
E. {2, 3}
A. {2, 3, 5, 13}
B. {4, 3, 5, 13}
C. {1, 4}
D. {1, 5, 4, 13}
E. {2, 3}
A. list
B. tuple
C. set
A. list
B. tuple
C. set
A. (1, 2, 1, 2)
B. [1, 2, 1, 2]
C. (1, 1, 2, 2)
D. [1, 1, 2, 2]
E. illegal
A. {1, 2, 4, 3, 1, 5, 4, 13}
B. {1, 2, 4, 3, 5, 13}
C. {1, 2, 4, 3}
D. {1, 5, 4, 13}
E. illegal
A. d = {}
B. d = {"john":40, "peter":45}
C. d = {40:"john", 45:"peter"}
D. d = (40:"john", 45:"peter")
C. 40 and 45
D. d = (40:"john", 45:"peter")
A. True
B. False
A. True
B. False
C. illegal
A. True
B. False
C. illegal
A. 40
B. 45
C. "john"
D. "peter"
A. d.delete("john":40)
B. d.delete("john")
C. del d["john"]
D. del d("john":40)
A. d.size()
B. len(d)
C. size(d)
D. d.len()
d = {"john":40, "peter":45}
print(list(d.keys()))
A. ["john", "peter"]
B. ["john":40, "peter":45]
C. ("john", "peter")
D. ("john":40, "peter":45)
D. Since "susan" is not a key in the set, Python raises a syntax error.
D. Since "susan" is not a key in the set, Python raises a syntax error.
A. [1, 2, 3]
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
A. [1, 2, 3]
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
A. [1, 2, 3]
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
A. [1, 2, 3]
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
A. {1, 2, 3}
B. {2, 1, 3}
C. {3, 2, 1}
D. {2, 3, 1}
E. {1, 2, 3, 2, 1, 3}
C. Infinite recursion can occur if recursion does not reduce the problem
in a manner that allows it to eventually converge into the base case.
def factorial(n):
if n == 0: # Base case
return 1
else:
return _____________________ # Recursive call
A. n * (n - 1)
B. n
C. n * factorial(n - 1)
D. factorial(n - 1) * n
def xfunction(n):
if n > 0:
print(n % 10)
xfunction(n // 10)
A. n > 0
B. n <= 0
C. no base cases
D. n < 0
Your answer is correct
15.4 Analyze the following recursive function.
def factorial(n):
return n * factorial(n - 1)
A. 3
B. 4
C. 5
D. 6
A. The Fibonacci series begins with 0 and 1, and each subsequent number
is the sum of the preceding two numbers in the series.
B. The Fibonacci series begins with 1 and 1, and each subsequent number
is the sum of the preceding two numbers in the series.
C. The Fibonacci series begins with 1 and 2, and each subsequent number
is the sum of the preceding two numbers in the series.
D. The Fibonacci series begins with 2 and 3, and each subsequent number
is the sum of the preceding two numbers in the series.
B. 15
C. 25
D. 31
E. 32
def fib(index):
if index == 0: # Base case
return 0
elif index == 1: # Base case
return 1
else: # Reduction and recursive calls
return _________________________
A. fib(index - 1)
B. fib(index - 2)
C. fib(index - 1) + fib(index - 2)
D. fib(index - 2) + fib(index - 1)
def xfunction(n):
if n == 1:
return 1
else
return n + xfunction(n - 1)
A. n is 1.
B. n is greater than 1.
C. n is less than 1.
D. no base case.
A. 12
B. 11
C. 10
D. 9
def isPalindrome(s):
if len(s) <= 1: # Base case
return True
elif _____________________________
return False
else:
return isPalindrome(s.substring(1, len(s) - 1))
x = [1, 2, 3, 4, 5]
xfunction(x, 5)
def isPalindrome(s):
return isPalindromeHelper(s, 0, len(s) - 1)
A. isPalindromeHelper(s)
def sort(lst):
_________________________ # Sort the entire list
B. sortHelper(lst, len(lst) - 1)
C. sortHelper(lst, 0, len(lst) - 1)
D. sortHelper(lst, 0, len(lst) - 2)
A. recursiveBinarySearchHelper(lst, key)
def main():
times = count("abcabc", 'a')
print(ch + " appears " + str(times) + (" times " if times > 1 else " time
") + "in " + s)
return result;
main()
A. 3
B. 7
C. 10
D. 14
A. 5
B. 10
C. 15
D. 20
A:
def xfunction(length):
if length > 1:
print(length - 1, end = " ")
xfunction(length - 1)
xfunction(5)
B:
def xfunction(length):
while length > 1:
print(length - 1, end = " ")
xfunction(length - 1)
xfunction(5)
def f1(n):
if n == 0:
return 0
else:
return n + f1(n - 1)
print(f1(3))
print(f2(3, 0))
print(f2(2, 0))
A. 0
B. 1
C. 2
D. 3