0% found this document useful (0 votes)
83 views

CSC212 Question Bank

This document contains a question bank for CSC212 with questions about computers, programming, and Python. It includes 31 multiple choice questions covering topics like hardware, software, binary numbers, storage devices, operating systems, Python history, syntax, errors, and graphics programming using the turtle module. The questions are compiled by LaPorche and Archimedes Jr.

Uploaded by

adediran olamide
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

CSC212 Question Bank

This document contains a question bank for CSC212 with questions about computers, programming, and Python. It includes 31 multiple choice questions covering topics like hardware, software, binary numbers, storage devices, operating systems, Python history, syntax, errors, and graphics programming using the turtle module. The questions are compiled by LaPorche and Archimedes Jr.

Uploaded by

adediran olamide
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND

ARCHIMEDES JR.)

chapter1; What is a Computer? C. because binary numbers are simplest.

D. because binary numbers are the bases upon


1.1 ________ is the physical aspect of the
which all other number systems are built.
computer that can be seen.

A. Hardware
1.5 One byte has ________ bits.
B. Software
A. 4
C. Operating system
B. 8
D. Application program
C. 12

D. 16
1.2 __________ is the brain of a computer.

A. Hardware

B. CPU 1.6 One gigabyte is approximately ________


bytes.
C. Memory
A. 1 million
D. Disk
B. 10 million

C. 1 billion
1.3 The speed of the CPU may be measured in
D. 1 trillion
__________.

A. megabytes

B. gigabytes 1.7 A computer?s _______ is volatile; that is, any


information stored in it is lost when the system?s
C. megahertz power is turned off.

D. gigahertz A. floppy disk

B. hard disk

1.4 Why do computers use zeros and ones? C. flash stick

A. because combinations of zeros and ones can D. CD-ROM


represent any numbers and characters.
E. memory
B. because digital devices have two stable states
and it is natural to use one state for 0 and the
other for 1. 1.8 Which of the following are storage devices?
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. floppy disk 1.12 ___________ translates high-level language


program into machine language program.
B. hard disk
A. An assembler
C. flash stick
B. A compiler
D. CD-ROM
C. CPU

D. The operating system


1.9 ____________ is a device to connect a
computer to a local area network (LAN).

A. Regular modem Section 1.4 Operating Systems

B. DSL 1.13 ____________ is an operating system.

C. Cable modem A. Java

D. NIC B. C++

C. Windows XP

Section 1.3 Programs D. Visual Basic

1.10 ____________ are instructions to the E. Python


computer.

A. Hardware
1.14 _____________ is a program that runs on a
B. Software computer to manage and control a computer's
activities.
C. Programs
A. Operating system
D. Keyboards
B. Python

C. Modem
1.11 Computer can execute the code in
____________. D. Interpreter

A. machine language E. Compiler

B. assembly language

C. high-level language Section 1.5 History of Python

D. none of the above 1.15 Python was created by ____________.

A. James Gosling
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. Bill Gates E. Pascal

C. Steve Jobs

D. Guido van Rossum Section 1.6 Getting Started with Python

E. Google 1.19 To start Python from the command prompt,


use the command ________.

A. execute python
1.16 Which of the following statements is true?
B. run python
A. Python 3 is a newer version, but it is backward
compatible with Python 2. C. python

B. Python 3 is a newer version, but it is not D. go python


backward compatible with Python 2.

C. A Python 2 program can always run on a


Python 3 interpreter. 1.20 To run python script file named t.py, use the
command ________.
D. A Python 3 program can always run on a
Python 2 interpreter. A. execute python t.py

B. run python t.py

1.17 ________ is an object-oriented programming C. python t.py


language.
D. go python t.py
A. Java

B. C++
1.21 Python syntax is case-sensitive.
C. C
A. True
D. C#
B. False
E. Python

1.22 Which of the following code is correct?


1.18 ________ is interpreted.

A. Python
A.
B. C++
print("Programming is fun")
C. C
print("Python is fun")
D. Ada
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. A. // comments //

print("Programming is fun") B. /* comments */

print("Python is fun") C. ''' comments '''

D. /# comments #/

C.

print("Programming is fun) Section 1.8 Programming Errors

print("Python is fun") 1.25 A ___________ error does not cause the


program to abort, but produces incorrect results.

A. syntax
D.
B. runtime
print("Programming is fun)
C. logic
print("Python is fun")

A. A
1.26 In Python, a syntax error is detected by the
B. B ________ at _________.

C. C A. compiler/at compile time

D. D B. interpreter/at runtime

C. compiler/at runtime
Section 1.7 Programming Style and D. interpreter/at compile time
Documentation

1.23 A Python line comment begins with


________. 1.27 Which of the following code is correct?

A. //

B. /* I:

C. # print("Programming is fun")

D. $$ print("Python")

print("Computer Science")

1.24 A Python paragraph comment uses the style


________.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

II: D. turtle.showturtle()

print("Programming is fun") E. turtle.showTurtle()

print("Python")

print("Computer Science") 1.29 To move the turtle to a point at (4, 5), use
___________.

A. turtle.move(4, 5)
III:
B. turtle.moveTo(4, 5)
print("Programming is fun")
C. turtle.moveto(4, 5)
print("Python")
D. turtle.go(4, 5)
print("Computer Science")
E. turtle.goto(4, 5)

IV:
1.30 To draw a circle with radius 50, use
print("Programming is fun") ___________.
print("Python") A. turtle.circle(50)

print("Computer Science") B. turtle.circle(100)

A. I C. turtle.drawcircle(50)
B. II D. turtle.drawCircle(50)
C. III

D. IV 1.31 To lift the pen, use ___________.

A. turtle.penUp()

Section 1.9 Getting Started with Graphics B. turtle.penup()


Programming
C. turtle.lift()
1.28 To show the current location and direction of
the turtle object, use ___________. D. turtle.up()

A. turtle.show()

B. turtle.showLocation() 1.32 To put the pen down, use ___________.

C. turtle.showDirection() A. turtle.penDown()
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. turtle.pendown()

C. turtle.putDown() # Compute average

D. turtle.down() average = (number1 + number2 + number3) / 3

Chapter 2 Elementary
Programming # Display result

print(average)

Section 2.3 Reading Input from the Console A. 1.0

2.1 What function do you use to read a string? B. 2.0

A. input("Enter a string") C. 3.0

B. eval(input("Enter a string")) D. 4.0

C. enter("Enter a string")

D. eval(enter("Enter a string")) 2.4 _______ is the code in natural language mixed


with some program code.

A. Python program
2.2 What is the result of eval("1 + 3 * 2")?
B. A Python statement
A. "1 + 3 * 2"
C. Pseudocode
B. 7
D. A flowchart diagram
C. 8

D. "1 + 6"
2.5 If you enter 1 2 3 in one line, when you run
this program, what will happen?

2.3 If you enter 1 2 3 in three separate lines, when


you run this program, what will be displayed?
print("Enter three numbers: ")

number1 = eval(input())
print("Enter three numbers: ")
number2 = eval(input())
number1 = eval(input())
number3 = eval(input())
number2 = eval(input())

number3 = eval(input())
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

# Compute average 2.8 An identifier can contain digits, but cannot


start with a digit?
average = (number1 + number2 + number3) / 3
A. true

B. false
# Display result

print(average)
2.9 Which of the following is a valid identifier?
A. The program runs correctly and displays 1.0
A. $343
B. The program runs correctly and displays 2.0
B. mile
C. The program runs correctly and displays 3.0
C. 9X
D. The program runs correctly and displays 4.0
D. 8+9
E. The program will have a runtime error on the
input. E. max_radius

2.6 You can place the line continuation symbol __ 2.10 Which of the following is a valid identifier?
at the end of a line to tell the interpreter that the
statement is continued on the next line. A. import

A. / B. mile1

B. \ C. MILE

C. # D. (red)

D. * E. "red"

E. &

Section 2.5 Variables, Assignment Statements, and


Expressions
Section 2.4 Identifiers
2.11 If you enter 1, 2, 3, in one line, when you run
2.7 An identifier cannot be a keyword? this program, what will be displayed?

A. true

B. false number1, number2, number3 =


eval(input("Enter three numbers: "))
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

# Compute average x = x + 2.5

average = (number1 + number2 + number3) / 3 print(x)

A. 1

# Display result B. 2

print(average) C. 3

A. 1.0 D. 3.5

B. 2.0 E. The statements are illegal

C. 3.0

D. 4.0 Section 2.6 Simultaneous Assignments

2.14 What will be displayed by the following


code?
2.12 What will be displayed by the following
code?

x, y = 1, 2

x=1 x, y = y, x

x=2*x+1 print(x, y)

print(x) A. 1 1

A. 0 B. 2 2

B. 1 C. 1 2

C. 2 D. 2 1

D. 3

E. 4 2.15 To following code reads two number. Which


of the following is the correct input for the code?

2.13 What will be displayed by the following


code? x, y = eval(input("Enter two numbers: "))

A. 1 2

x=1 B. "1 2"


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. 1, 2 B. 1.0 / 2

D. 1, 2, C. 1 // 2

D. 1.0 // 2

Section 2.8 Numeric Data Types and Operators E. 1 / 2.0

2.16 What is the result of 45 / 4?

A. 10 2.20 Which of the following expression results in


a value 1?
B. 11
A. 2 % 1
C. 11.25
B. 15 % 4
D. 12
C. 25 % 5

D. 37 % 6
2.17 In the expression 45 / 4, the values on the left
and right of the / symbol are called ____.

A. operators 2.21 25 % 1 is _____

B. operands A. 1

C. parameters B. 2

D. arguments C. 3

D. 4

2.18 What is the result of 45 // 4? E. 0

A. 10

B. 11 2.22 24 % 5 is _____

C. 11.25 A. 1

D. 12 B. 2

C. 3

2.19 Which of the following expressions will yield D. 4


0.5?
E. 0
A. 1 / 2
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

2.23 2 ** 3 evaluates to __________. C. y is 2 because x + 1 is assigned to x and then x


is assigned to y.
A. 9
D. The program has a compile error since x is
B. 8 redeclared in the statement int y = x = x + 1.
C. 9.0

D. 8.0 2.27 Which of the following is equivalent to


0.025?

A. 0.25E-1
2.24 2 ** 3.0 evaluates to __________.
B. 2.5e-2
A. 9
C. 0.0025E1
B. 8
D. 0.00025E2
C. 9.0
E. 0.0025E+1
D. 8.0

2.28 If a number is too large to be stored in


2.25 2 * 3 ** 2 evaluates to __________.
memory, it _____________.
A. 36
A. causes overflow
B. 18
B. causes underflow
C. 12
C. causes no error
D. 81
D. cannot happen in Python

2.26 What is y displayed in the following code?


Section 2.9 Evaluating Expressions and Operator
Precedence

x=1 2.29 What is the result of evaluating 2 + 2 ** 3 /


2?
y=x=x+1
A. 4
print("y is", y)
B. 6
A. y is 0.
C. 4.0
B. y is 1 because x is assigned to y first.
D. 6.0
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

y=1

Section 2.10 Augmented Assignment Operators x *= y + 1

2.30 What is the value of i printed? A. x is 1.

B. x is 2.

j=i=1 C. x is 3.

i += j + j * 5 D. x is 4.

print("What is i?", i)

A. 0 2.33 To add a value 1 to variable x, you write

B. 1 A. 1 + x = x

C. 5 B. x += 1

D. 6 C. x := 1

E. 7 D. x = x + 1

E. x = 1 + x

2.31 What is x after the following statements?

2.34 Which of the following statements are the


same?
x=1

x *= x + 1
(A) x -= x + 4
A. x is 1
(B) x = x + 4 - x
B. x is 2
(C) x = x - (x + 4)
C. x is 3
A. (A) and (B) are the same
D. x is 4
B. (A) and (C) are the same

C. (B) and (C) are the same


2.32 What is x after the following statements?
D. (A), (B), and (C) are the same

x=2
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

2.35 To add number to sum, you write (Note: x *= y + 1


Python is case-sensitive)
A. x is 1
A. number += sum
B. x is 2
B. number = sum + number
C. x is 3
C. sum = Number + sum
D. x is 4
D. sum += number

E. sum = sum + number


Section 2.11 Type Conversions and Rounding

2.39 Which of the following functions return 4.


2.36 Suppose x is 1. What is x after x += 2?
A. int(3.4)
A. 0
B. int(3.9)
B. 1
C. round(3.4)
C. 2
D. round(3.9)
D. 3

E. 4
2.40 Which of the following functions cause an
error?

2.37 Suppose x is 1. What is x after x -= 1? A. int("034")

A. 0 B. eval("034")

B. 1 C. int("3.4")

C. 2 D. eval("3.4")

D. -1

E. -2 Section 2.12 Case Study: Displaying the Current


Time

2.41 The time.time() returns ________________ .


2.38 What is x after the following statements?
A. the current time.

B. the current time in milliseconds.


x=1
C. the current time in milliseconds since
y=2 midnight.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. the current time in milliseconds since B. 3


midnight, January 1, 1970.
C. 5
E. the current time in milliseconds since
midnight, January 1, 1970 GMT (the Unix time). D. 4

E. 3.0

3.4 What is round(6.5)?


Chapter 3 Mathematical Functions,
Strings, and Objects A. 4

B. 5

Section 3.2 Common Python Functions C. 6

3.1 What is max(3, 5, 1, 7, 4)? D. 7

A. 1 E. 8

B. 3

C. 5 3.5 What is round(7.5)?

D. 7 A. 4

E. 4 B. 5

C. 6

3.2 What is min(3, 5, 1, 7, 4)? D. 7

A. 1 E. 8

B. 3

C. 5 3.6 Is pow(a, b) the same as a ** b?

D. 7 A. Yes

E. 4 B. No

3.3 What is round(3.52)? 3.7 What is math.degrees(math.pi / 2)?

A. 3.5 A. 0.0
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. 90.0 B. brackets

C. 45.0 C. single-quotes

D. 30.0 D. double-quotes

E. braces

3.8 What is math.radians(30) * 6?

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

B. 1.3434343 A. A

C. 3.141592653589793 B. B

D. 5.565656 C. C

D. D

3.9 What is math.sin(math.pi / 6)?

A. 1.0 3.13 Suppose x is a char variable with a value 'b'.


What will be displayed by the statement
B. 1.3434343 print(chr(ord(x) + 1))?

C. 3.141592653589793 A. a

D. 0.5 B. b

C. c
Section 3.3 Strings and Characters D. d
3.10 Which of the following is the correct
expression of character 4?
3.14 Which of the following statement prints
A. 4 smith\exam1\test.txt?
B. "4" A. print("smith\exam1\test.txt")
C. '4' B. print("smith\\exam1\\test.txt")

C. print("smith\"exam1\"test.txt")

3.11 In Python, a string literal is enclosed in D. print("smith"\exam1"\test.txt")


__________.

A. parentheses
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

3.15 Suppose i is an int type variable. Which of A. Good123


the following statements display the character
whose Unicode is stored in variable i? B. Good6

A. print(i) C. Good 123

B. print(str(i)) D. Illegal expression

C. print(int(i))

D. print(chr(i)) 3.20 What will be displayed by the following


code?

3.16 The Unicode of 'a' is 97. What is the Unicode


for 'c'? print("A", end = ' ')

A. 96 print("B", end = ' ')

B. 97 print("C", end = ' ')

C. 98 print("D", end = ' ')

D. 99 A. ABCD

B. A, B, C, D

3.17 Will print(chr(4)) display 4? C. A B C D

A. Yes D. A, B, C, D will be displayed on four lines

B. No
3.21 Which of the following statements is correct?

3.18 What will be displayed by print(ord('z') - A. s = "Chapter " + 1


ord('a'))?
B. s = "Chapter " + str(1)
A. 25

B. 26
Section 3.5 Introduction to Objects and Methods
C. a
3.22 What is the type for object 5.6?
D. z
A. int

B. float
3.19 The expression "Good " + 1 + 2 + 3 evaluates
C. str
to ________.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

Section 3.6 Formatting Numbers and Strings

3.23 Which of the following statements are true? 3.27 The format function returns _______.

A. Each object has a unique id. A. an int

B. Objects of the same type have the same id. B. a float

C. Objects of the same kind have the same type. C. a str

D. A variable that holds a value is actually a


reference to an object for the value.
3.28 To format a number x to 3 digits after the
decimal point, use _______.

3.24 Suppose s = "Welcome", what is type(s)? A. format(x, "5.3f")

A. int B. format("5.3f", x)

B. float C. format(x, "5.4f")

C. str D. format("5.3f", x)

D. String

3.29 Suppose x is 345.3546, what is format(x,


"10.3f")? (note b represents a blank space)
3.25 Suppose s is "Welcome", what is s.upper()?
A. bb345.355
A. welcome
B. bbb345.355
B. WELCOME
C. bbbb345.355
C. Welcome
D. bbb345.354

E. bbbb345.354
3.26 Suppose s is "\t\tWelcome\n", what is
s.strip()?

A. \t\tWelcome\n 3.30 What will be displayed by the following


code? ? (note ? represents a blank space)
B. \t\tWelcome\n

C. \t\tWELCOME\n
print(format("Welcome", "10s"), end = '#')
D. Welcome
print(format(111, "4d"), end = '#')

print(format(924.656, "3.2f"))
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. ???Welcome#?111#924.66

B. Welcome#111#924.66 Section 3.7 Drawing Various Shapes

C. Welcome#111#.66 3.33 To set the pen size to 5 pixels, use _________.

D. Welcome???#?111#924.66 A. turtle.setSize(5)

B. turtle.size(5)

3.31 What will be displayed by the following C. turtle.pensize(5)


code? ? (note ? represents a blank space)
D. turtle.setPenSize(5)

print(format("Welcome", ">10s"), end = '#')


3.34 To undo the last turtle action, use _________.
print(format(111, "<4d"), end = '#')
A. turtle.rollback()
print(format(924.656, ">10.2f"))
B. turtle.redo()
A. ???Welcome#?111#924.66
C. turtle.undo()
B. ???Welcome#?111#????924.66
D. turtle.remove()
C. ???Welcome#111?#????924.66

D. Welcome???#111?#????924.66
3.35 To set a turtle drawing speed to 5, use
_________.

3.32 Suppse number contains integer value 4, A. turtle.speed(5)


which of the following statement is correct?
B. turtle.setSpeed(5)
A. print(format(number, "2d"), format(number
** 1.5, "4d")) C. turtle.setspeed(5)

B. print(format(number, "2d"), format(number D. turtle.velocity(5)


** 1.5, "4.2d"))

C. print(format(number, "2d"), format(number


3.36 To draw a circle of diameter 10 with filled
** 1.5, "4.2f"))
color red, use _________.
D. print(format(number, "2f"), format(number
A. turtle.circle(5, "red")
** 1.5, "4.2f"))
B. turtle.circle(10, "red")
E. print(format(number, "2.1f"), format(number
** 1.5, "4.2f")) C. turtle.dot(5, "red")
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. turtle.dot(10, "red")

Chapter 4 Selections Section 4.3 Generating Random Numbers

4.4 To generate a random integer between 0 and


5, use ________________.
Section 4.2 Boolean Types, Values, and
A. random.randint(0, 5)
Expressions
B. random.randint(0, 6)
4.1 The "less than or equal to" comparison
operator is __________. C. random.randrange(0, 5)

D. random.randrange(0, 6)
A. <

B. <= 4.5 random.randint(0, 1) returns ____________.


C. =< A. 0
D. << B. 1
E. != C. 0 or 1

D. 2
4.2 The equal comparison operator is
__________.
4.6 random.random() returns ____________.
A. <>
A. a float number i such that 0 < i < 1.0
B. !=
B. a float number i such that 0 <= i < 1.0
C. ==
C. a float number i such that 0 <= i <= 1.0
D. =
D. a float number i such that 0 < i < 2.0

4.3 The word True is ________.


Sections 4.4-4.10
A. a Python keyword
4.7 Which of the following code displays the area
B. a Boolean literal of a circle if the radius is positive.
C. same as value 1 A. if radius != 0: print(radius * radius * 3.14159)
D. same as value 0 B. if radius >= 0: print(radius * radius * 3.14159)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. if radius > 0: print(radius * radius * 3.14159)

D. if radius <= 0: print(radius * radius * 3.14159) even = False

if even = True:

4.8 What is the output of the following code? print("It is even!")

A. The program has a syntax error in line 1 (even


= False)
x=0
B. The program has a syntax error in line 2 if
if x < 4: even = True is not a correct condition. It should be
replaced by if even == True: or if even:.
x=x+1
C. The program runs, but displays nothing.

D. The program runs and displays It is even!.


print("x is", x)

A. x is 0
4.11 Analyze the following code.
B. x is 1

C. x is 2
even = False
D. x is 3
if even:
E. x is 4
print("It is even!")

A. The code displays It is even!


4.9 Suppose isPrime is a boolean variable, which
of the following is the correct and best statement B. The code displays nothing.
for testing if isPrime is true.
C. The code is wrong. You should replace if even:
A. if isPrime = True: with if even == True:
B. if isPrime == True: D. The code is wrong. You should replace if even:
with if even = True:
C. if isPrime:

D. if not isPrime = False:


4.12 Suppose x = 1, y = -1, and z = 1. What will be
E. if not isPrime == False:
displayed by the following statement?

4.10 Analyze the following code:


if x > 0:
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

if y > 0:

print("x > 0 and y > 0") Code 1:

elif z > 0:

print("x < 0 and z > 0") if number % 2 == 0:

A. x > 0 and y > 0 even = True

B. x < 0 and z > 0 else:

C. x < 0 and z < 0 even = False

D. nothing displayed

Code 2:

4.13 The following code displays ___________.

even = number % 2 == 0

temperature = 50 A. Code 1 has compile errors.

B. Code 2 has compile errors.

if temperature >= 100: C. Both Code 1 and Code 2 have compile errors.

print("too hot") D. Both Code 1 and Code 2 are correct, but Code
2 is better.
elif temperature <= 40:

print("too cold")
4.15 Suppose income is 4001, what will be
else: displayed by f the following code?

print("just right")

A. too hot if income > 3000:


B. too cold print("Income is greater than 3000")
C. just right elif income > 4000:
D. too hot too cold just right print("Income is greater than 4000")

A. none
4.14 Analyze the following code: B. Income is greater than 3000
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. Income is greater than 3000 followed by print("Cannot get a driver's license")


Income is greater than 4000
elif age >= 16:
D. Income is greater than 4000
print("Can get a driver's license")
E. Income is greater than 4000 followed by
Income is greater than 3000
IV:

4.16 Suppose you write the code to display if age < 16:
"Cannot get a driver's license" if age is less than
print("Cannot get a driver's license")
16
elif age == 16:

print("Can get a driver's license")


and "Can get a driver's license" if age is greater
than or equal to 16. elif age > 16:
Which of the following code is correct? print("Can get a driver's license")

A. I and II
I: B. II and III
if age < 16: C. I, II, and III
print("Cannot get a driver's license") D. III and IV
if age >= 16: E. All correct
print("Can get a driver's license")

4.17 Suppose you write the code to display


"Cannot get a driver's license" if age is less than
II:
16
if age < 16:

print("Cannot get a driver's license")


and "Can get a driver's license" if age is greater
else: than or equal to 16.

print("Can get a driver's license") Which of the following code is the best?

III: I:

if age < 16: if age < 16:


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

print("Cannot get a driver's license") C. III

if age >= 16: D. IV

print("Can get a driver?s license")

4.18 The __________ function immediately


terminates the program.
II:
A. sys.terminate()
if age < 16:
B. sys.halt()
print("Cannot get a driver's license")
C. sys.exit()
else:
D. sys.stop()
print("Can get a driver's license")

Section 4.11 Logical Operators


III:
4.19 Which of the Boolean expressions below is
if age < 16: incorrect?
print("Cannot get a driver's license") A. True and 3 => 4

elif age >= 16: B. !(x > 0) and (x > 0)

print("Can get a driver's license") C. (x > 0) or (x < 0)

D. (x != 0) or (x = 0)
IV: E. (-10 < x < 0)
if age < 16:

print("Cannot get a driver's license") 4.20 Which of the following is the correct
expression that evaluates to True if the number x
elif age == 16:
is between 1 and 100 or the number is negative?
print("Can get a driver's license")

elif age > 16:


21. To check whether a char variable ch is an
print("Can get a driver's license") uppercase letter, you write ___________.

A. I A. (ch >= 'A' and ch >= 'Z')

B. II B. (ch >= 'A' and ch <= 'Z')

C. (ch >= 'A' or ch <= 'Z')


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. ('A' <= ch <= 'Z') D. x != 5

4.21 Given |x - 2| <= 4, Which of the following is 4.25 Assume x = 4 and y = 5, Which of the
true? following is true?

A. x - 2 <= 4 and x - 2 >= 4 A. not (x == 4)

B. x - 2 <= 4 and x - 2 > -4 B. x != 4

C. x - 2 <= 4 and x - 2 >= -4 C. x == 5

D. x - 2 <= 4 or x - 2 >= -4 D. x != 5

4.22 Given |x - 2| >= 4, Which of the following is 4.26 Which of the following is equivalent to x !=
true? y?

A. x - 2 >= 4 and x - 2 <= -4 A. not (x == y)

B. x - 2 >= 4 or x - 2 <= -4 B. x > y and x < y

C. x - 2 >= 4 and x - 2 < -4 C. x > y or x < y

D. x - 2 >= 4 or x - 2 <= -4 D. x >= y or| x <= y

4.23 Assume x = 4 and y = 5, Which of the


following is true?
4.27 What will be displayed by the following
A. x < 5 and y < 5 code?

B. x < 5 or y < 5

C. x > 5 and y > 5 ch = 'F'

D. x > 5 or y > 5 if ch >= 'A' and ch <= 'Z':

print(ch)

4.24 Assume x = 4 and y = 5, Which of the A. F


following is true?
B. f
A. not (x == 4)
C. nothing
B. x != 4
D. F f
C. x == 5
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

Section 4.14 Conditional Expressions

4.28 What is y after the following statement is


executed?
A. Code 2 has a syntax error, because you cannot
have True and False literals in the conditional
expression.
x=0
B. Code 3 has a syntax error, because you
y = 10 if x > 0 else -10 attempt to assign number to even.

A. -10 C. All three are correct, but Code 1 is preferred.


B. 0 D. All three are correct, but Code 2 is preferred.
C. 10 E. All three are correct, but Code 3 is preferred.
D. 20

E. Illegal expression 4.30 What will be displayed by the following


code?

4.29 Analyze the following code fragments that


assign a boolean value to the variable even. isCorrect = False

print("Correct" if isCorrect else "Incorrect")


Code 1: A. Correct
if number % 2 == 0: B. Incorrect

even = True C. nothing


else: D. Correct Incorrect
even = False

Section 4.15 Operator Precedence and


Associativity
Code 2:
4.31 The order of the precedence (from high to
even = True if number % 2 == 0 else False
low) of the operators +, *, and, or is:

A. and, or, *, +
Code 3:
B. *, +, and, or
even = number % 2 == 0
C. *, +, and, or
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. *, +, or, and

E. or, and, *, + count = 0

while count < 10:

4.32 Which of the following operators are right- print("Welcome to Python")


associative.
count += 1
A. *
A. 8
B. +
B. 9
C. %
C. 10
D. and
D. 11
E. =
E. 0
4.33 What is the value of the following
expression?

True or True and False 5.2 What is the output of the following code?

A. True

B. False x=0

4.34 Which of the following statements are True? while x < 4:

A. (x > 0 and x < 10) is same as (x > 0 and x < 10) x=x+1

B. (x > 0 or x < 10) is same as (0 < x < 10)

C. (x > 0 or x < 10 and y < 0) is same as (x > 0 or print("x is", x)


(x < 10 and y < 0))
A. x is 0
D. (x > 0 or x < 10 and y < 0) is same as ((x > 0 or
B. x is 1
x < 10) and y < 0)
C. x is 2
Chapter 5 Loops
D. x is 3

E. x is 4
Section 5.2 The while Loop

5.1 How many times will the following code print


"Welcome to Python"? 5.3 Analyze the following code.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

E. infinite number of times

count = 0

while count < 100: 5.5 What will be displayed when the following
code is executed?
# Point A

print("Welcome to Python!")
number = 6
count += 1
while number > 0:
# Point B
number -= 3

print(number, end = ' ')


# Point C
A. 6 3 0
A. count < 100 is always True at Point A
B. 6 3
B. count < 100 is always True at Point B
C. 3 0
C. count < 100 is always False at Point B
D. 3 0 -3
D. count < 100 is always True at Point C
E. 0 -3
E. count < 100 is always False at Point C

Section 5.3 The for Loop


5.4 How many times will the following code print
"Welcome to Python"? 5.6 Analyze the following statement:

count = 0 sum = 0

while count < 10: for d in range(0, 10, 0.1):

print("Welcome to Python") sum += sum + d

A. The program has a syntax error because the


range function cannot have three arguments.
A. 8
B. The program has a syntax error because the
B. 9 arguments in the range must be integers.
C. 10 C. The program runs in an infinite loop.
D. 11 D. The program runs fine.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

5.8 The function range(5) return a sequence


______________.
5.7 Which of the following loops prints "Welcome
to Python" 10 times? A. 1, 2, 3, 4, 5

B. 0, 1, 2, 3, 4, 5

A: C. 1, 2, 3, 4

for count in range(1, 10): D. 0, 1, 2, 3, 4

print("Welcome to Python")

5.9 Which of the following function returns a


sequence 0, 1, 2, 3?
B:
A. range(0, 3)
for count in range(0, 10):
B. range(0, 4)
print("Welcome to Python")
C. range(3)

D. range(4)
C:

for count in range(1, 11):


5.10 Which of the following function is incorrect?
print("Welcome to Python")
A. range(0, 3.5)

B. range(10, 4, -1)
D:
C. range(1, 3, 1)
for count in range(1, 12):
D. range(2.5, 4.5)
print("Welcome to Python")
E. range(1, 2.5, 4.5)
A. BD

B. ABC
5.11 Which of the following loops correctly
C. AC computes 1/2 + 2/3 + 3/4 + ... + 99/100?
D. BC

E. AB A:

sum = 0

for i in range(1, 99):


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

sum += i / (i + 1) B. ABCD

C. B

print("Sum is", sum) D. CDE

E. CD

B:

sum = 0 5.12 The following loop displays


_______________.
for i in range(1, 100):

sum += i / (i + 1)
for i in range(1, 11):

print(i, end = " ")


print("Sum is", sum)
A. 1 2 3 4 5 6 7 8 9

B. 1 2 3 4 5 6 7 8 9 10
C:
C. 1 2 3 4 5
sum = 0
D. 1 3 5 7 9
for i in range(1.0, 99.0):
E. 2 4 6 8 10
sum += i / (i + 1)

5.13 What is the output for y?


print("Sum is", sum)

y=0
D:
for i in range(0, 10):
sum = 0
y += i
for i in range(1.0, 100.0):

sum += i / (i + 1)
print(y)

A. 10
print("Sum is", sum)
B. 11
A. BCD
C. 12
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. 13 D. 20

E. 45

5.16 Given the following four patterns,

5.14 What is the output for y?

Pattern A Pattern B Pattern C


Pattern D
y=0
1 123456 1 123456
for i in range(0, 10, 2):
12 12345 21 12345
y += i
123 1234 321 1234

1234 123 4321 123


print(y)
12345 12 54321 12
A. 9
123456 1 654321 1
B. 10

C. 11

D. 20
Which of the pattern is produced by the following
code?
5.15 What is the output for y?

for i in range(1, 6 + 1):


y=0 for j in range(6, 0, -1):

for i in range(10, 1, -2): print(j if j <= i else " ", end = " ")
y += i print()

A. Pattern A
print(y) B. Pattern B
A. 10 C. Pattern C
B. 40 D. Pattern D
C. 30
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

Section 5.5 Minimizing Numerical Errors for j in range(10):

5.17 Analyze the following fragment: print(i * j)

A. 100

sum = d = 0 B. 20

while d != 10.0: C. 10

d += 0.1 D. 45

sum += sum + d

A. The program does not run because sum and d 5.20 How many times is the print statement
are not initialized correctly. executed?

B. The program never stops because d is always


0.1 inside the loop.
for i in range(10):
C. The program may not stop because of the
phenomenon referred to as numerical inaccuracy for j in range(i):
for operating with floating-point numbers.
print(i * j)
D. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... +
A. 100
1.9
B. 20

C. 10
5.18 To add 0.01 + 0.02 + ... + 1.00, what order
should you use to add the numbers to get better D. 45
accuracy?

A. add 0.01, 0.02, ..., 1.00 in this order to a sum


variable whose initial value is 0. Section 5.7 Keywords break and continue

B. add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order 5.21 Will the following program terminate?
to a sum variable whose initial value is 0.

balance = 10
Section 5.6 Case Studies

5.19 How many times is the print statement


executed? while True:

if balance < 9: break

for i in range(10): balance = balance - 9


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. Yes sum += item

B. No if sum >= 4: continue

5.22 What is sum after the following loop print(sum)


terminates?
A. 15

B. 16
sum = 0
C. 17
item = 0
D. 18
while item < 5:

item += 1
5.24 Will the following program terminate?
sum += item

if sum > 4: break


balance = 10

print(sum)
while True:
A. 5
if balance < 9: continue
B. 6
balance = balance - 9
C. 7
A. Yes
D. 8
B. No

5.23 What is sum after the following loop


terminates? Section 5.8 Case Study: Displaying Prime
Numbers

5.25 What will be displayed by after the following


sum = 0 loop terminates?

item = 0

while item < 5: number = 25

item += 1 isPrime = True


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

i=2 C. i is 6 isPrime is True

while i < number and isPrime: D. i is 6 isPrime is False

if number % i == 0:

isPrime = False 5.27 What is the number of iterations in the


following loop:

i += 1
for i in range(1, n):

# iteration
print("i is", i, "isPrime is", isPrime)
A. 2*n
A. i is 5 isPrime is True
B. n
B. i is 5 isPrime is False
C. n - 1
C. i is 6 isPrime is True
D. n + 1
D. i is 6 isPrime is False

5.28 What is the number of iterations in the


5.26 What will be displayed by after the following following loop:
loop terminates?

for i in range(1, n + 1):


number = 25
# iteration
isPrime = True
A. 2*n
for i in range(2, number):
B. n
if number % i == 0:
C. n - 1
isPrime = False
D. n + 1
break

5.29 Suppose the input for number is 9. What will


print("i is", i, "isPrime is", isPrime) be displayed by the following program?
A. i is 5 isPrime is True

B. i is 5 isPrime is False number = eval(input("Enter an integer: "))


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

isPrime = True 6.2 The header of a function consists of


____________.
for i in range(2, number):
A. function name
if number % i == 0:
B. function name and parameter list
isPrime = False
C. parameter list

print("i is", i)
6.3 A function _________.

A. must have at least one parameter


if isPrime:
B. may have no parameters
print(number, "is prime")
C. must always have a return statement to return
break a value
else: D. must always have a return statement to return
multiple values
print(number, "is not prime")

A. i is 3 followed by 9 is prime
Sections 6.3 Calling a Function
B. i is 3 followed by 9 is not prime
6.4 Arguments to functions always appear within
C. i is 2 followed by 9 is prime
__________.
D. i is 2 followed by 9 is not prime
A. brackets

Chapter 6 Functions B. parentheses

Sections 6.2 Defining a Function C. curly braces

6.1 If a function does not return a value, by D. quotation marks


default, it returns ___________.

A. None
6.5 Does the function call in the following
B. int function cause syntax errors?

C. double

D. public import math

E. null def main():


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

math.sin(math.pi) A. void

B. nothing

main() C. 0

A. Yes D. None

B. No

6.9 Consider the following incomplete code:

6.6 Each time a function is invoked, the system


stores parameters and local variables in an area of
memory, known as _______, which stores def f(number):
elements in last-in first-out fashion.
# Missing function body
A. a heap

B. storage area
print(f(5))
C. a stack

D. an array
The missing function body should be ________.

A. return "number"
Sections 6.4 Functions With/Without Return
B. print(number)
Values
C. print("number")
6.7 Which of the following should be defined as a
None function? D. return number
A. Write a function that prints integers from 1 to
100.
Sections 6.5 Positional and Keyword Arguments
B. Write a function that returns a random integer
from 1 to 100. 6.10 Given the following function header:

C. Write a function that checks whether a


number is from 1 to 100.
def f(p1, p2, p3, p4)
D. Write a function that converts an uppercase
letter to lowercase.
Which of the following is correct to invoke it?

6.8 A function with no return statement returns A. f(1, 2, 3, 4)


______.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. f(p1 = 1, 2, 3, 4) n -= 1

C. f(p1 = 1, p2 = 2, p3 = 3, 4)

D. f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) What will be displayed by the call nPrint('a', 4)?

E. f(1, 2, 3, p4 = 4) A. aaaaa

B. aaaa

6.11 Given the following function C. aaa

D. invalid call

def nPrint(message, n): E. infinite loop

while n > 0:

print(message) 6.13 Given the following function

n -= 1

def nPrint(message, n):

What will be displayed by the call nPrint('a', 4)? while n > 0:

print(message)

A. aaaaa n -= 1

B. aaaa

C. aaa What is k after invoking nPrint("A message", k)?

D. invalid call

E. infinite loop k=2

nPrint("A message", k)

6.12 Given the following function A. 0

B. 1

def nPrint(message, n): C. 2

while n > 0: D. 3

print(message)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

6.14 Given the following function 6.16 A variable defined inside a function is
referred to as __________.

A. a global variable
def nPrint(message, n):
B. a function variable
while n > 0:
C. a block variable
print(message)
D. a local variable
n -= 1

6.17 A variable defined outside a function is


What is k after invoking nPrint("A message", k)? referred to as __________.

A. a global variable

k=2 B. a function variable


nPrint(n = k, message = "A message") C. a block variable
A. 0 D. a local variable
B. 1

C. 2 6.18 Whenever possible, you should avoid using


__________.
D. 3
A. global variables

B. function parameters
Sections 6.6 Passing Parameters by Values
C. global constants
6.15 When you invoke a function with a
parameter, the value of the argument is passed to D. local variables
the parameter. This is referred to as _________.

A. function invocation
6.19 What will be displayed by the following
B. pass by value code?
C. pass by reference

D. pass by name x=1

def f1():

Section 6.9 The Scope of Variables y=x+2


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

print(y)

6.21 What will be displayed by the following


code?
f1()

print(x)
x=1
A. 1 3
def f1():
B. 3 1
x=x+2
C. The program has a runtime error because x is
not defined. print(x)

D. 1 1

E. 3 3 f1()

print(x)

6.20 What will be displayed by the following A. 1 3


code?
B. 3 1

C. The program has a runtime error because x is


x=1 not defined.

def f1(): D. 1 1

x=3 E. 3 3

print(x)

6.22 What will be displayed by the following


code?
f1()

print(x)
x=1
A. 1 3
def f1():
B. 3 1
global x
C. The program has a runtime error because x is
not defined. x=x+2

D. 1 1 print(x)

E. 3 3
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

f1() 6.24 What will be displayed by the following


code?
print(x)

A. 1 3
def f1(x = 1, y = 2):
B. 3 1
x=x+y
C. The program has a runtime error because x is
not defined. y += 1

D. 1 1 print(x, y)

E. 3 3

f1(2, 1)

Section 6.10 Default Arguments A. 1 3

6.23 What will be displayed by the following B. 2 3


code?
C. The program has a runtime error because x
and y are not defined.

def f1(x = 1, y = 2): D. 3 2

x=x+y E. 3 3

y += 1

print(x, y) 6.25 What will be displayed by the following


code?

f1()
def f1(x = 1, y = 2):
A. 1 3
x=x+y
B. 3 1
y += 1
C. The program has a runtime error because x
and y are not defined. print(x, y)

D. 1 1

E. 3 3 f1(y = 2, x = 1)

A. 1 3

B. 2 3
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. The program has a runtime error because x


and y are not defined.
Function Abstraction and Stepwise Refinement
D. 3 2
6.28 __________ is to implement one function in
E. 3 3 the structure chart at a time from the top to the
bottom.

A. Bottom-up approach
6.26 Which of the following function headers is
correct? B. Top-down approach

A. def f(a = 1, b): C. Bottom-up and top-down approach

B. def f(a = 1, b, c = 2): D. Stepwise refinement

C. def f(a = 1, b = 1, c = 2):

D. def f(a = 1, b = 1, c = 2, d): 6.29 __________ is a simple but incomplete


version of a function.

A. A stub
Section 6.11 Returning Multiple Values
B. A function
6.27 What will be displayed by the following
code? C. A function developed using botton-up
approach

D. A function developed using top-down


def f1(x = 1, y = 2): approach
return x + y, x - y
Chapter 7 Objects and Classes

x, y = f1(y = 2, x = 1)
Section 7.2 Defining Classes for Objects
print(x, y)
7.1 __________ represents an entity in the real
A. 1 3 world that can be distinctly identified.

B. 3 1 A. A class

C. The program has a runtime error because the B. An object


function returns the multiple values
C. A method
D. 3 -1
D. A data field
E. -1 3
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

7.2 _______ is a template, blueprint, or contract 7.6 The ________ creates an object in the memory
that defines objects of the same type. and invokes __________.

A. A class A. the __init__ method

B. An object B. the init method

C. A method C. the initialize method

D. A data field D. the __str__ method

7.3 An object is an instance of a __________. 7.7 Analyze the following code:

A. program

B. class class A:

C. method def __init__(self, s):

D. data self.s = s

7.4 The keyword __________ is required to define def print(self):


a class.
print(s)
A. def

B. return
a = A("Welcome")
C. class
a.print()
D. All of the above.
A. The program has an error because class A
does not have a constructor.

7.5 ________ is used to create an object. B. The program has an error because class A
should have a print method with signature
A. A constructor print(self, s).
B. A class C. The program has an error because class A
should have a print method with signature
C. A value-returning method
print(s).
D. A None method
D. The program would run if you change print(s)
to print(self.s).
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

print(self.s)

7.8 Analyze the following code:

a = A()

class A: a.print()

def __init__(self, s): A. The program has an error because class A


does not have a constructor.
self.s = s
B. The program has an error because s is not
defined in print(s).
def print(self): C. The program runs fine and prints nothing.
print(self.s) D. The program has an error because the
constructor is invoked without an argument.

E. The program runs fine and prints Welcome.


a = A()

a.print()
7.10 Given the declaration x = Circle(), which of
A. The program has an error because class A
the following statement is most accurate.
does not have a constructor.
A. x contains an int value.
B. The program has an error because s is not
defined in print(s). B. x contains an object of the Circle type.
C. The program runs fine and prints nothing. C. x contains a reference to a Circle object.

D. The program has an error because the D. You can assign an int value to x.
constructor is invoked without an argument.

Section 7.4 Hiding Data Fields


7.9 Analyze the following code:
7.11 Analyze the following code:

class A:
class A:
def __init__(self, s = "Welcome"):
def __init__(self):
self.s = s
self.x = 1

self.__y = 1
def print(self):
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. The program has an error because x is private


and cannot be access outside of the class.
def getY(self):
B. The program has an error because y is private
return self.__y and cannot be access outside of the class.

C. The program has an error because you cannot


name a variable using __y.
a = A()
D. The program runs fine and prints 1.
print(a.x)
E. The program runs fine and prints 0.
A. The program has an error because x is private
and cannot be access outside of the class.

B. The program has an error because y is private 7.13 Analyze the following code:
and cannot be access outside of the class.

C. The program has an error because you cannot


name a variable using __y. class A:

D. The program runs fine and prints 1. def __init__(self):

E. The program runs fine and prints 0. self.x = 1

self.__y = 1

7.12 Analyze the following code:

def getY(self):

class A: return self.__y

def __init__(self):

self.x = 1 a = A()

self.__y = 1 a.x = 45

print(a.x)

def getY(self): A. The program has an error because x is private


and cannot be access outside of the class.
return self.__y
B. The program has an error because y is private
and cannot be access outside of the class.
a = A() C. The program has an error because you cannot
name a variable using __y.
print(a.__y)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. The program runs fine and prints 1. self.__y = 1

E. The program runs fine and prints 45.

def getY(self):

7.14 In the following code, return self.__y

def A: a = A()

def __init__(self): a.__y = 45

__a = 1 print(a.getX())

self.__b = 1 A. The program has an error because x is private


and cannot be access outside of the class.
self.__c__ = 1
B. The program has an error because y is private
__d__ = 1 and cannot be access outside of the class.

C. The program has an error because you cannot


name a variable using __y.
# Other methods omitted
D. The program runs fine and prints 1.

E. The program runs fine and prints 45.


Which of the following is a private data field?

A. __a
7.16 Which of the following statement is most
B. __b
accurate?
C. __c__

D. __d__
A. A reference variable is an object.

B. A reference variable refers to an object.


7.15 Analyze the following code:
C. An object may contain other objects.

D. An object may contain the references of other


class A: objects.

def __init__(self):

self.x = 1 7.17 What is the value of times displayed?


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

def main(): B. 2

myCount = Count() C. 3

times = 0 D. 4

E. -1

for i in range(0, 100):

increment(myCount, times) 8.2 What is max("Programming is fun")?

A. P

print("myCount.count =", myCount.count, B. r


"times =", times)
C. a blank space character
def increment(c, times):
D. u
c.count += 1
E. n
times += 1

class Count:
8.3 What is min("Programming is fun")?
def __init__(self):
A. P
self.count = 0
B. r
main()
C. a blank space character
A. count is 101 times is 0
D. u
B. count is 100 times is 0
E. n
C. count is 100 times is 100

D. count is 101 times is 101


8.4 What is "Programming is fun"[4: 6]?
Chapter 8 More on Strings and A. ram
Special Methods
B. ra

C. r
Section 8.2 The str Class
D. pr
8.1 What is len("Good")?
E. pro
A. 1
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. Programming is f

8.5 What is "Programming is fun"[-1]? D. Programming is fu

A. Pr E. Programming is

B. P

C. fun 8.9 What is "Programming is fun"[:2]?

D. n A. Pr

E. un B. P

C. Pro

8.6 What is "Programming is fun"[1:1]? D. Programming

A. P E. Programming is

B. r

C. Pr 8.10 Given a string s = "Welcome", which of the


following code is incorrect?
D. ''
A. print(s[0])
E. incorrect expression
B. print(s.lower())

C. s[1] = 'r'
8.7 What is "Programming is fun"[-3:-1]?
D. print(s.strip())
A. Pr

B. P
8.11 What will be displayed by the following
C. fun code?
D. un

E. fu class Count:

def __init__(self, count = 0):


8.8 What is "Programming is fun"[:-1]? self.__count = count
A. Programming

B. rogramming is fun c1 = Count(2)


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

c2 = Count(2) 8.14 Given a string s = "Programming is fun",


what is s.find('rom')?
print(id(c1) == id(c2), end = " ")
A. 1

B. 2
s1 = "Good"
C. 3
s2 = "Good"
D. 4
print(id(s1) == id(s2))
E. -1
A. True False

B. True True
8.15 Given a string s = "Programming is fun",
C. False True what is s.rfind('m')?

D. False False A. 8

B. 7

8.12 Given a string s = "Welcome", what is C. 6


s.count('e')?
D. 5
A. 1
E. -1
B. 2

C. 3
8.16 Given a string s = "Programming is fun",
D. 4 what is s.find('m')?

A. 8

8.13 Given a string s = "Programming is fun", B. 7


what is s.find('ram')?
C. 6
A. 1
D. 5
B. 2
E. -1
C. 3

D. 4
8.17 Given a string s = "Programming is fun",
E. -1 what is s.startswith('m')?

A. 0
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. 1 E. False

C. -1

D. True 8.21 What is "Good".replace("o", "e")?

E. False A. God

B. Good

8.18 Given a string s = "Programming is fun", C. Geed


what is s.startswith('Program')?
D. Ged
A. 0
E. Good
B. 1

C. -1
8.22 Analyze the following code:
D. True

E. False
class Name:

def __init__(self, firstName, mi, lastName):


8.19 Given a string s = "Programming is fun",
what is s.endswith('fun')? self.firstName = firstName

A. 0 self.mi = mi

B. 1 self.lastName = lastName

C. -1

D. True firstName = "John"

E. False name = Name(firstName, 'F', "Smith")

firstName = "Peter"

8.20 Given a string s = "Programming is fun", name.lastName = "Pan"


what is s.endswith('m')?
print(name.firstName, name.lastName)
A. 0
A. The program displays Peter Pan.
B. 1
B. The program displays John Pan.
C. -1
C. The program displays Peter Smith.
D. True
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. The program displays John Smith. D. The program displays no thing.

8.23 Analyze the following code: Section 8.5 Operator Overloading and Special
Methods

8.24 To concatenate two strings s1 and s2 into s3,


class MyDate: use _________.

def __init__(self, year, month, day): A. s3 = s1 + s2


self.year = year B. s3 = s1.add(s2)
self.month = month C. s3 = s1.__add(s2)
self.day = day D. s3 = s1.__add__(s2)

class Name: 8.25 To retrieve the character at index 3 from


string s, use _________.
def __init__(self, firstName, mi, lastName,
birthDate): A. s[3]
self.firstName = firstName B. s.getitem(3)
self.mi = mi C. s.__getitem__(3)

self.lastName = lastName D. s.getItem(3)


self.birthDate = birthDate

8.26 To return the length of string s, use


_________.
birthDate = MyDate(1990, 1, 1)
A. s.__len__()
name = Name("John", 'F', "Smith", birthDate)
B. len(s)
birthDate = MyDate(1991, 1, 1)
C. size(s)
birthDate.year = 1992
D. s.size()
print(name.birthDate.year)

A. The program displays 1990.


8.27 If a class defines the __str__(self) method, for
B. The program displays 1991.
an object obj for the class, you can use ______ to
C. The program displays 1992. invoke the __str__ method.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. obj.__str__() D. window = Tk()

B. str(obj)

C. obj.str() 9.2 How do you create a frame?

D. __str__(obj) A. frame = newWindow()

B. frame = Window()

8.28 To check whether string s1 contains s2, use C. frame = Frame()


_________.
D. frame = Tk()
A. s1.__contains__(s2)

B. s1 in s2
9.3 How do you create an event loop?
C. s1.contains(s2)
A. window.loop()
D. si.in(s2)
B. window.main()

C. window.mainloop()
8.29 Suppose i is 2 and j is 4, i + j is same as
_________. D. window.eventloop()

A. i.__add(j)

B. i.__add__(j) 9.4 To create a label under parent window, use


_______.
C. i.__Add(j)
A. label = Label(text = "Welcome to Python")
D. i.__ADD(j)
B. label = Label(window, text = "Welcome to
Chapter 9 GUI Programming Using Python")

Tkinter C. label = Label(text = "Welcome to Python", fg


= " red")

D. label = Label(text = "Welcome to Python", fg


Sections 9.2-9.4 = " red", bg = "white")

9.1 How do you create a window?

A. window = newWindow() 9.5 To create a button under parent window with


command processButton, use _______.
B. window = Window()
A. Button(text = "OK", fg = "red", command =
C. window = Frame()
processButton)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. Button(window, text = "OK", fg = "red") C. Checkbutton(frame1, text = "Bold", variable =


v1, command = processCheckbutton)
C. Button(window, text = "OK", fg = "red")
D. Radiobutton(frame1, text = "Yellow", bg =
D. Button(window, text = "OK", command = "yellow", variable = v1, value = 1, command =
processButton) processRadiobutton)

9.6 Assume v1 = IntVar(), how do you set a new 9.9 Assume name = StringVar(), how do you
value 5 to v1. create a text field (entry) under parent frame2
with variable bound to name?
A. v1 = 5
A. entryName = Entry(frame2, textvariable =
B. v1.setValue(5)
name)
C. v1.set(5)
B. entryName = Entry(frame2, variable = name,
D. v1.get(5) value = "")

C. entryName = Entry(frame2, textvariable =


name, command = processEntry)
9.7 Assume v1 = IntVar(), how do you create a
check button under parent frame1 with variable D. entryName = Entry(frame2, text = name,
bound to v1? command = processEntry)

A. Checkbutton(frame1, text = "Bold", command


= processCheckbutton)
9.10 How do you create a GUI component for
B. Checkbutton(frame1, text = "Bold", variable = displaying multiple-lines of text?
v1.get())
A. use Label
C. Checkbutton(frame1, text = "Bold", variable =
B. Use Button
v1, command = processCheckbutton)
C. Use Text
D. Checkbutton(frame1, text = "Bold", variable =
v1.set(), command = processCheckbutton) D. Use Message

9.8 Assume v1 = IntVar(), how do you create a 9.11 How do you create a text area?
radio button under parent frame1 with variable
bound to v1 and value 1? A. use Label

A. Checkbutton(frame1, text = "Bold", command B. Use Button


= processCheckbutton)
C. Use Text
B. Checkbutton(frame1, text = "Bold", variable =
v1.get()) D. Use Message
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. canvas.create_circle(100 - 100, 100 - 100, 100 +


100, 100 + 100)
Section 9.5

9.12 How do you create a canvas under parent


frame1 with background color white and 9.15 How do you draw an arc centered at 100, 100
foregroung color green? with radius 20, starting angle 15, ending angle 50,
filled with red color on canvas?
A. Canvas(frame1, bg = "white", fg = "green")
A. canvas.create_arc(100 - 20, 100 - 20, 100 + 20,
B. Canvas(frame1, bg = "white", fg = "green", 100 + 20, fill = "red", start = 15, extent = 50)
command = processEvent)
B. canvas.create_arc(100 - 20, 100 - 20, 100 + 20,
C. Canvas(frame1, bg = "white", command = 100 + 20, fill = "red", start = 15, extent = 35)
processEvent)
C. canvas.create_arc(100 - 20, 100 - 20, 100 + 20,
D. Canvas(frame1, fg = "green", command = 100 + 20, filled = "red", start = 15, extent = 50)
processEvent)
D. canvas.create_arc(100 - 20, 100 - 20, 100 + 20,
100 + 20, fill = "red", start = 15, end = 50)
Section 9.5

9.13 How do you draw a rectangle centered at 9.16 How do you draw a red line from 100, 100 to
100, 100 with width 100 and height 100 on canvas? 400, 500?
A. canvas.create_rect(100, 100, 100, 100) A. canvas.create_line(100, 100, 100, 500, fill =
"red")
B. canvas.create_rectangle(100, 100, 100, 100)
B. canvas.create_line(100, 100, 400, 100, fill =
C. canvas.create_rect(100 - 50, 100 - 50, 100 + 50,
"Red")
100 + 50)
C. canvas.create_line(100, 100, 400, 500, filled =
D. canvas.create_rectangle(100 - 50, 100 - 50, 100
"red")
+ 50, 100 + 50)
D. canvas.create_line(100, 100, 400, 500, fill =
"red")
9.14 How do you draw a circle rectangle centered
at 100, 100 with radius 100 on canvas?
9.17 How do you draw a polygon consisting of
A. canvas.create_oval(100, 100, 100, 100)
points (30, 40), (50, 50), (10, 100) filled with red
B. canvas.create_oval(100 - 100, 100 - 100, 100 + color?
100, 100 + 100)
A. canvas.create_poly(30, 40, 50, 50, 10, 100, fill =
C. canvas.create_oval(100 - 50, 100 - 50, 100 + 50, "red")
100 + 50)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. canvas.create_polygon(30, 40, 50, 50, 10, 100, C. place manager


filled = "red")
D. flow manager
C. canvas.create_polygon(30, 40, 50, 50, 10, 100,
fill = "red")

D. canvas.create_polygon((30, 40), (50, 50), (10, 9.21 Which option do you use to put the
100), fill = "red") components in a container using the pack
manager in the same row?

A. component.pack(LEFT)
9.18 How do you display a text "Good morning"
centered at 30, 40 with color red? B. component.pack(side = LEFT)

A. canvas.create_text(30, 40, text = "Good C. component.pack(side = "LEFT")


morning", fill = "red")
D. component.pack("LEFT")
B. canvas.create_polygon(30, 40, 50, 50, 10, 100,
filled = "red")
9.22 The side option of the pack manager may be
C. canvas.create_polygon(30, 40, 50, 50, 10, 100,
_____________.
fill = "red")
A. LEFT
D. canvas.create_polygon((30, 40), (50, 50), (10,
100), fill = "red") B. RIGHT

C. BOTTOM
Section 9.6 The Geometry Managers D. TOP
9.19 _______ are geometry managers in Tkinter.

A. pack 9.23 Using a grid manager, you can use the option
_________ to place a component in multiple rows
B. grid
and columns.
C. place
A. row
D. flow
B. column

C. rowspan
9.20 To place a button in a specified row and
D. columnspan
column in its parent container, use ________.

A. pack manager
Section 9.8 Displaying Images
B. grid manager
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

9.24 To create an image, use C. menubar = Menu()


______________________.
D. menubar = MenBar()
A. image = PhotoImage(imagefilename)

B. image = Image(file = imagefilename)


9.28 To add a menu in a menubar, use
C. image = PhotoImage(file = imagefilename) __________

D. image = PhotoImage(imagefilename) A. menu1 = Menu(menubar)

B. menu1 = menu(menubar)

9.25 You can create an image from a C. menu1 = Menu(winodw)


____________ file.
D. menu1 = Menu()
A. .png

B. .gif
9.29 To add a menubar, use __________
C. .bmp
A. window.configure(menu = menubar)
D. .jpg
B. window.config(menubar)

C. window.config(menu = menubar)
9.26 You can display an image in
______________. D. window.configure(menubar)

A. a label

B. a button Sections 9.10-9.11

C. a check button 9.30 To display a popup menu, use __________

D. a radio button A. menu.display()

E. an entry B. menu.post()

C. menu.display(300, 300)

Section 9.9 Menus D. menu.post(300, 300)

9.27 To create a menu in a window, use


__________
9.31 To bind a canvas with a left mouse click
A. menubar = Menu(window) event p, use __________

B. menubar = MenBar(window) A. canvas.left(p)


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. canvas.bind("<Button-1>", p)

C. canvas.bind("Button-1", p) 9.35 The event _____________ is fired when the


right mouse button is released.
D. canvas.bind(<Button-1>, p)
A. <ButtonReleased-1>

B. <ButtonReleased-2>
9.32 To bind a canvas with a right mouse click
event p, use __________ C. <ButtonReleased-3>

A. canvas.left(p) D. <ButtonPressed-1>

B. canvas.bind("<Button-1>", p) E. <ButtonPressed-2>

C. canvas.bind("Button-1", p)

D. canvas.bind(<Button-1>, p) 9.36 The event _____________ is fired when the


right mouse button is double-clicked.
E. canvas.bind("<Button-3>", p)
A. <Double-Button-1>

B. <Double-Button-2>
9.33 To bind a canvas with a mouse entered event
p, use __________ C. <Double-Button-3>

A. canvas.entered(p) D. <Triple-Button-1>

B. canvas.bind("<Enter>", p) E. <Triple-Button-2>

C. canvas.bind("<Entered>", p)

D. canvas.bind(<Enter>, p) 9.37 To bind a canvas with a key event p, use


__________

A. canvas.entered(p)
9.34 The event _____________ is fired when the
mouse is moved while the middle mouse is being B. canvas.bind("<Enter>", p)
held down.
C. canvas.bind("<Key>", p)
A. <B1-Motion>
D. canvas.bind(<Enter>, p)
B. <B2-Motion>
E. canvas.bind("<Enter>", p)
C. <B3-Motion>

D. <Button-1>
9.38 The mouse event object has the property
E. <Button-2> ____________.
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. x

B. y 9.41 To display an error dialog named "Variable


is not assigned", use __________
C. widget
A. tkinter.messagebox.showinfo("showinfo",
D. X "Variable is not assigned")
E. Y B.
tkinter.messagebox.showwarning("showwarning"
, "Variable is not assigned")
Section 9.14 Standard Dialogs
C. tkinter.messagebox.showerror("showerror",
9.39 To display a message dialog named "Variable is not assigned")
"Programming is fun", use __________
D. tkinter.messagebox.askyesno("ashyesno",
A. tkinter.messagebox.showinfo("showinfo", "Variable is not assigned")
"Programming is fun")

B.
9.42 To display an input dialog named "Is this an
tkinter.messagebox.showwarning("showwarning"
integer?", use __________
, "Programming is fun")
A. tkinter.messagebox.showinfo("showinfo", "Is
C. tkinter.messagebox.showerror("showerror",
this an integer?")
"Programming is fun")
B.
D. tkinter.messagebox.askyesno("ashyesno",
tkinter.messagebox.showwarning("showwarning"
"Programming is fun")
, "Is this an integer?")

C. tkinter.messagebox.showerror("showerror",
9.40 To display a warning dialog named "Is this an integer?")
"Variable is assigned, but not used", use
D. tkinter.messagebox.askyesno("ashyesno", "Is
__________
this an integer?")
A. tkinter.messagebox.showinfo("showinfo",
"Variable is assigned, but not used") Chapter 10 Lists
B.
tkinter.messagebox.showwarning("showwarning"
, "Variable is assigned, but not used") Section 10.2 List Basics

C. tkinter.messagebox.showerror("showerror", 10.1 __________ creates a list.


"PVariable is assigned, but not used")
A. list1 = list()
D. tkinter.messagebox.askyesno("ashyesno", B. list1 = []
"Variable is assigned, but not used")
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

C. list1 = list([12, 4, 4]) 10.5 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is min(list1)?
D. list1 = [12, 4, 4]
A. 5
E. list1 = [1, "3", "red"]
B. 4

C. 8
10.2 What is list("abcd")?
D. 25
A. ['a', 'b', 'c', 'd']
E. 1
B. ['ab']

C. ['cd']
10.6 Suppose list1 is [1, 3, 2], what is sum(list1)?
D. ['abcd']
A. 5

B. 4
10.3 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is len(list1)? C. 6

A. 6 D. 2

B. 7 E. 1

C. 8

D. 5 10.7 To shuffle list1, use _______.

E. 4 A. list1.shuffle()

B. shuffle(list1)

10.4 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what C. random.shuffle(list1)


is max(list1)?
D. random.shuffleList(list1)
A. 5

B. 4
10.8 Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], Which of
C. 8 the following is correct?

D. 25 A. print(list1[0])

E. 1 B. print(list1[:2])

C. print(list1[:-2])
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

D. print(list1[4:6]) D. [0.0, 0.5, 1.0, 1.5, 2.0]

10.9 Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is 10.13 list1 = [11, 2, 23] and list2 = [11, 2, 2], list1 <
list1[-1]? list2 is ________

A. 3 A. True

B. 5 B. False

C. 1

D. 0 10.14 list1 = [11, 2, 23] and list2 = [2, 11, 23], list1
== list2 is ________

A. True
10.10 Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is
list1[:-1]? B. False

A. 0

B. [1, 3, 2, 4, 5, 2, 1] 10.15 To add 5 to the end of list1, use _______.

C. [1, 3, 2, 4, 5, 2] A. list1.add(5)

D. [1, 3, 2, 4, 5, 2, 1, 0] B. list1.append(5)

C. list1.addLast(5)

10.11 Suppose list1 is [1, 3, 2], What is list1 * 2? D. list1.addEnd(5)

A. [2, 6, 4]

B. [1, 3, 2, 1, 3] 10.16 To insert 5 to the third position in list1, use


_______.
C. [1, 3, 2, 1, 3, 2]
A. list1.insert(3, 5)
D. [1, 3, 2, 3, 2, 1]
B. list1.insert(2, 5)

C. list1.add(3, 5)
10.12 Suppose list1 = [0.5 * x for x in range(0, 4)],
list1 is ________ D. list1.append(3, 5)

A. [0, 1, 2, 3]

B. [0, 1, 2, 3, 4] 10.17 To remove string "red" from list1, use


_______.
C. [0.0, 0.5, 1.0, 1.5]
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

A. list1.remove("red") 10.21 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what


is list1 after list1.reverse()?
B. list1.remove(red)
A. [3, 4, 5, 20, 5, 25, 1, 3]
C. list1.removeAll("red")
B. [1, 3, 3, 4, 5, 5, 20, 25]
D. list1.removeOne("red")
C. [25, 20, 5, 5, 4, 3, 3, 1]

D. [1, 3, 4, 5, 20, 5, 25, 3]


10.18 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is list1.index(5)? E. [3, 1, 25, 5, 20, 5, 4, 3]

A. 0

B. 4 10.22 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what


is list1 after list1.extend([34, 5])?
C. 1
A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
D. 2
B. [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]

C. [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]


10.19 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is list1.count(5)? D. [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]

A. 0 E. [3, 1, 25, 5, 20, 5, 4, 3, 34, 5]

B. 4

C. 1 10.23 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what


is list1 after list1.pop(1)?
D. 2
A. [3, 4, 5, 20, 5, 25, 1, 3]

B. [1, 3, 3, 4, 5, 5, 20, 25]


10.20 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is list1 after list1.sort()? C. [3, 5, 20, 5, 25, 1, 3]

A. [3, 4, 5, 20, 5, 25, 1, 3] D. [1, 3, 4, 5, 20, 5, 25]

B. [1, 3, 3, 4, 5, 5, 20, 25] E. [3, 1, 25, 5, 20, 5, 4]

C. [25, 20, 5, 5, 4, 3, 3, 1]

D. [1, 3, 4, 5, 20, 5, 25, 3] 10.24 Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what
is list1 after list1.pop()?

A. [3, 4, 5, 20, 5, 25, 1]


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

B. [1, 3, 3, 4, 5, 5, 20, 25] indexOfMax = i

C. [3, 5, 20, 5, 25, 1, 3]

D. [1, 3, 4, 5, 20, 5, 25] print(indexOfMax)

E. [3, 1, 25, 5, 20, 5, 4] A. 0

B. 1

10.25 "Welcome to Python".split() is ________ C. 2

A. ["Welcome", "to", "Python"] D. 3

B. ("Welcome", "to", "Python") E. 4

C. {"Welcome", "to", "Python"}

D. "Welcome", "to", "Python" 10.28 What will be displayed by the following


code?

10.26 What is list("a#b#c#d".split('#')?


myList = [1, 2, 3, 4, 5, 6]
A. ['a', 'b', 'c', 'd']
for i in range(1, 6):
B. ['a b c d']
myList[i - 1] = myList[i]
C. ['a#b#c#d']

D. ['abcd']
for i in range(0, 6):

print(myList[i], end = " ")


10.27 What will be displayed by the following
code? A. 2 3 4 5 6 1

B. 6 1 2 3 4 5

myList = [1, 5, 5, 5, 5, 1] C. 2 3 4 5 6 6

max = myList[0] D. 1 1 2 3 4 5

indexOfMax = 0 E. 2 3 4 5 6 1

for i in range(1, len(myList)):

if myList[i] > max: Section 10.6 Copying Lists

max = myList[i]
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

10.29 What will be displayed by the following


code?
10.31 What will be displayed by the following
code?

list1 = [1, 3]

list2 = list1 def f(value, values):

list1[0] = 4 v=1

print(list2) values[0] = 44

A. [1, 3]

B. [4, 3] t=3

C. [1, 4] v = [1, 2, 3]

D. [1, 3, 4] f(t, v)

print(t, v[0])

Sections 10.7-10.8 A. 1 1

10.30 What will be displayed by the following B. 1 44


code?
C. 3 1

D. 3 44
def f(values):

values[0] = 44
10.32 What will be displayed by the following
code?

v = [1, 2, 3]

f(v) def f(i, values = []):

print(v) values.append(i)

A. [1, 44] return values

B. [1, 2, 3, 44]

C. [44, 2, 3] f(1)

D. [1, 2, 3] f(2)
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

v = f(3) A. at index 3

print(v) B. at index 4

A. [1] [2] [3] C. at index 5

B. [1] [1, 2] [1, 2, 3] D. at index 6

C. [1, 2, 3]

D. 1 2 3 Section 10.11 Sorting Lists

10.36 Use the selectionSort function presented in


this section to answer this question. Assume lst is
Section 10.10 Searching Lists [3.1, 3.1, 2.5, 6.4, 2.1], what is the content of list
after the first iteration of the outer loop in the
10.33 For the binarySearch function in Section
function?
10.10.2, what is low and high after the first
iteration of the while loop when invoking A. 3.1, 3.1, 2.5, 6.4, 2.1
binarySearch([1, 4, 6, 8, 10, 15, 20], 11)?
B. 2.5, 3.1, 3.1, 6.4, 2.1
A. low is 0 and high is 6
C. 2.1, 2.5, 3.1, 3.1, 6.4
B. low is 0 and high is 3
D. 3.1, 3.1, 2.5, 2.1, 6.4
C. low is 3 and high is 6
E. 2.1, 3.1, 2.5, 6.4, 3.1
D. low is 4 and high is 6

E. low is 0 and high is 5


10.37 Use the selectionSort function presented in
this section to answer this question. What is list1
after executing the following statements?
10.34 If a key is not in the list, the binarySearch
function returns _________.

A. insertion point list1 = [3.1, 3.1, 2.5, 6.4]


B. insertion point - 1 selectionSort(list1)
C. -(insertion point + 1) A. list1 is 3.1, 3.1, 2.5, 6.4

D. -insertion point B. list1 is 2.5 3.1, 3.1, 6.4

C. list1 is 6.4, 3.1, 3.1, 2.5


10.35 If the binary search function returns -4, D. list1 is 3.1, 2.5, 3.1, 6.4
where should the key be inserted if you wish to
insert the key into the list?
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

CSC 212 Solution . 24. C

Chapter 1 25. C

1. A 26. B

2. B 27. D

3. D\ C 28. D

4. B 29. E

5. B 30. A

6. C 31. B

7. E 32. B

8. All Options Correct

9. D Chapter 2

10. B and C 1. A

11. A 2. B

12. A 3. B

13. C 4. C

14. A 5. E

15. D 6. B

16. B 7. A

17. Option A, B, D and E 8. A

18. A 9. Option B and E

19. C 10.Option B and C

20. C 11. B

21. A 12. D

22. B 13. D

23. C 14. D
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

15. C 40. Option B and C

16. B 41. E

17. C CHAPTER 3

18. B 1. D

19. Option A, B and E 2. A

20. D 3. D

21. E 4. C

22. D 5. E

23. B 6. A

24. D 7. B

25. B 8. C

26. C 9. D

27. All Options are Correct 10. Option B and C

28. A 11. Option C and D

29. D 12. B

30. E 13. C

31. B 14. B

32. D 15. D

33. Option B, D and E 16. D

34. B 17. B

35. Option D and E 18. A

36. D 19. D

37. A 20. C

38. C 21. B

39. D 22. B
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

23. Option A , C and D 10. B

24. C 11. B

25. B 12. D

26. D 13. C

27. C 14. D

28. A 15. B

29. B 16. E

30. D 17. B

31. C 18. C

32. Option C, D and E 19. Option A, B and D

33. C 20. Option B and D

34. C 21. C

35. A 22. B

36. D 23. B

24. D

Chapter 4 25. D

1. B 26. Option A and C

2. C 27. A

3. Option A and B 28. A

4. Option A and D 29. E

5. C 30. B

6. B 31. C

7. C 32. E

8. B 33. A

9. C 34. Option A and C


CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

24. B

Chapter 5 25. D

1. C 26. B

2. E 27. B

3. Option A and e 28. B

4. E 29. C

5. C

6. B CHAPTER 6

7. D 1. A

8. D 2. B

9. Option B and D 3. B

10. Option A, D and E 4. B

11. B 5. B

12. B 6. C

13. E 7. A

14. D 8. D

15. C 9. D

16. C 10. Option A, D and E

17. C 11. B

18. A 12. E

19. A 13. C

20. D 14. C

21. A 15. B

22. B 16. D

23. A 17. A
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

18. A 12. B

19. B 13. E

20. B 14. B

21. C 15. B

22.E 16 Option B and D

23. E 17. B

24. D CHAPTER 8

25. E 1D

26. C 2D

27. D 3C

28. B 4B

29. A 5D

6D

CHAPTER 7 7 The correct answer is E


Explanation: The str [-3: -1] function returns a string
1. B with the last two characters. 'Programming is fun'[-
3:0] would return fun.
2. A
8D
3. B
9A
4. C
10 C
5. A
11 C
6. A
12 B
7. D
13 D
8. D
14 E
9. E
15 B
10. C
16 C
11. D
17 E
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

18 D 12 A

19 D 13 D

20 E 15 B

21 C 16 D

22 B 17 C

23 A 18 A

24 A/D 19 ABC

25 AC 20 B

26 AB 21 B

27AB 22 ALL OF THE ABOVE

28 AB 23 C/D

29 B 24 C

30 25 B

CHAPTER 9 26 ABCD

1D 27 A

2 C 28 A

3C 29 C

4B 30 D

5D 31 B

6C 32 E

7C 33 B

8D 34 B

9A 35 C

10 D 36 C

11 C 37 C
CSC212 QUESTION BANK (COMPLIED BY LAPORCH AND
ARCHIMEDES JR.)

38 ABC 19 D

39 A 20 B

40 B 21 E

41 C 22 A

42 D 23 C

24 A

CHAPTER 10 25 A

1 ALL OF THE ABOVE 26 A

2A 28 C

3C 29 B

4D 30 C

5E 31 D

6C 32 C

7C 33 D

8 ABCD 34 C

9D 35 A

10 B 36 E

11 C 37 D

12 B

13 B

14 B

15 B

16 A

17 A

18 D

You might also like