0% found this document useful (0 votes)
20 views79 pages

Self-Quiz Unit 1

The document contains a self-quiz with multiple-choice questions related to Python programming concepts, including data types, expressions, functions, and programming principles. Each question tests the understanding of specific Python syntax and functionality. The quiz is divided into units, covering various topics in programming.

Uploaded by

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

Self-Quiz Unit 1

The document contains a self-quiz with multiple-choice questions related to Python programming concepts, including data types, expressions, functions, and programming principles. Each question tests the understanding of specific Python syntax and functionality. The quiz is divided into units, covering various topics in programming.

Uploaded by

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

Self-Quiz Unit 1

Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "4" called?

Question 1Select one:


a.
a function
b.
an operator
c.
a prompt
d.
a statement
e.
a value
Clear my choice
Question 2
Not yet answered
Marked out of 1.00
Flag question
Question text
Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "print" called?

Question 2Select one:


a.
a function
b.
an operator
c.
a prompt
d.
a statement
e.
a value
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "print(2 + 2)" called?

Question 3Select one:


a.
a function
b.
an operator
c.
a prompt
d.
a statement
e.
a value
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
Programming languages are ______ languages that have been designed to express computations.
Question 4Select one:
a.
informal
b.
mathematical
c.
formal
d.
natural
e.
logical
Clear my choice
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
Which one of the following Python expressions has the value 64?
Question 5Select one:
a.
8^2
b.
8 ** 2
c.
8 +- 2
d.
8 += 2
e.
8 -+ 2
Clear my choice
Question 6
Not yet answered
Marked out of 1.00
Flag question
Question text
A program is a sequence of instructions that specifies how to perform a computation.
Question 6Select one:
True
False
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
Which one of the following Python expressions computes the number of miles in 5 km, where
one mile is 1.61 km?
Question 7Select one:
a.
5 * 1.61
b.
5 / 1.61
c.
1.61 / 5
d.
1.61 + 5
e.
miles = "5 km"
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
What is Python’s response to the command: type(0.123)
Question 8Select one:
a.
<class 'float'>
b.
<class 'bool'>
c.
SyntaxError: invalid syntax
d.
<class 'int'>
e.
<class 'str'>
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
Which one of the following Python expressions generates a syntax error?
Question 9Select one:
a.
8^2
b.
8 ** 2
c.
8 +- 2
d.
8 += 2
e.
8 -+ 2
Clear my choice
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
string is a Python type that represents sequences of numeric values.
Question 10Select one:
True
False
Self-Quiz Unit 2
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following is an invalid Python assignment statement?
Question 1Select one:
a.
a = b = 123
b.
‘3’ = 3
c.
x = int(“123”)
d.
y = None
e.
z = “hi” * 10
Clear my choice
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following statements?

pi = float(3.14159)
print (pi)
Question 2Select one:
a.
3
b.
3.0
c.
3.14159
d.
0
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
When a Python function is called, inside the function, the arguments are assigned to variables
called parameters.
Question 3Select one:
True
False
Question 4
Not yet answered
Marked out of 1.00
Flag question
Question text
1. What is the output of the code below assuming that global variable x has value 2 and
global y has value 3?
def f1():
return "ab"
def f2():
return f1() * x
def f3():
return f2() + f1() * y
print(f3())
Question 4Select one:
a.
ababababababababab
b.
abababababab
c.
abababab
d.
ababab
e.
ababababab
Clear my choice
Question 5
Not yet answered
Marked out of 1.00
Flag question
Question text
What is the output of the following statements?

pi = int(3.14159)
print (pi)
Question 5Select one:
a.
3
b.
3.0
c.
3.14159
d.
0
Clear my choice
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following Python statement produce?

>>> print ((1,000,000))


Question 6Select one:
a.
1,000
b.
1,000,000
c.
(1, 0, 0)
d.
Error invalid type
Clear my choice
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
A script usually contains a sequence of statements. If there is more than one statement, the results
appear one at a time as the statements execute.
Question 7Select one:
True
False
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
Match concepts with their definition!

A statement
that creates a Answer 1 Question
new variable 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
and gives it a nt statementexpressionoperandstatementvaluestrconcatenate
value.

Information Answer 2 Question


in a program
that is meant
for other
programmers
(or anyone
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
reading the
nt statementexpressionoperandstatementvaluestrconcatenate
source code)
and has no
effect on the
execution of
the program.

The ability to
combine
simple
expressions
and
statements
into
Answer 3 Question
compound
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
statements
nt statementexpressionoperandstatementvaluestrconcatenate
and
expressions in
order to
represent
complex
computations
concisely.

To join two Answer 4 Question


operands end- 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
to-end. nt statementexpressionoperandstatementvaluestrconcatenate

What the
Python
Answer 5 Question
interpreter
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
does to an
nt statementexpressionoperandstatementvaluestrconcatenate
expression to
find its value.

A Answer 6 Question
combination 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
of variables,
operators, and
values that
nt statementexpressionoperandstatementvaluestrconcatenate
represents a
single result
value.

A Python data
type that Answer 7 Question
stores 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
floating-point nt statementexpressionoperandstatementvaluestrconcatenate
numbers.

A Python data
type that
Answer 8 Question
holds positive
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
and negative
nt statementexpressionoperandstatementvaluestrconcatenate
whole
numbers.

A reserved
word that is
Answer 9 Question
used by the
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
interpreter to
nt statementexpressionoperandstatementvaluestrconcatenate
parse
programs.

One of the
values on Answer 10 Question
which an 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
operator nt statementexpressionoperandstatementvaluestrconcatenate
operates.

A special Answer 11 Question


symbol that 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
represents a nt statementexpressionoperandstatementvaluestrconcatenate
simple
computation
like addition,
multiplication
, or string
concatenation
.

A unit of code
that the Answer 12 Question
Python 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
interpreter nt statementexpressionoperandstatementvaluestrconcatenate
can execute.

A Python data
Answer 13 Question
type that
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
holds a string
nt statementexpressionoperandstatementvaluestrconcatenate
of characters.

A number or
letter that can
Answer 14 Question
be stored in a
8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
variable or
nt statementexpressionoperandstatementvaluestrconcatenate
evaluated in
an expression.

A name that Answer 15 Question


refers to a 8Choose...commentevaluateoperatorvariableintcompositionfloatkeywordassignme
value. nt statementexpressionoperandstatementvaluestrconcatenate

Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
The acronym PEMDAS is a way to remember the order of operations in Python.
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00
Flag question
Question text
What do we call the value provided to a function when the function is called (which is assigned
to the corresponding parameter in the function)?
Question 10Select one:
a.
argument
b.
return value
c.
method
d.
the special value None
e.
global variable
Self-Quiz Unit 3
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python statements?
x=5
if x % 2 == 1:
print (x)
else:
print (x, x%2)

Question 1Select one:


a.
5
b.
(5, 1)
c.
2
d.
(5, 0)
Clear my choice
Question 2
Not yet answered
Marked out of 1.00
Flag question
Question text
What is the output of the following Python statements?
percentage = ( 60 * 100) // 55
print (percentage)
Question 2Select one:
a.
percentage
b.
109
c.
109.0909090909091
d.
109.0
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
Match the following terms and definitions

Answer 1 Question 3Choose...flow of


The order in which statements are executed during a
executionfunction callstack
program run.
diagramheaderlocal variable

Answer 2 Question 3Choose...flow of


The first part of a compound statement, begins with
executionfunction callstack
a keyword and ends with a colon ( : )
diagramheaderlocal variable

A statement that executes a function. It consists of Answer 3 Question 3Choose...flow of


the name of the function followed by a list of executionfunction callstack
arguments enclosed in parentheses. diagramheaderlocal variable

Answer 4 Question 3Choose...flow of


A variable defined inside a function that can only be
executionfunction callstack
used inside its function.
diagramheaderlocal variable

Answer 5 Question 3Choose...flow of


A graphical representation of functions, their
executionfunction callstack
variables, and the values to which they refer.
diagramheaderlocal variable

Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following python command produce:

>>> percentage = float ( 60 * 100) / 55


>>> print (percentage)
Question 4Select one:
a.
percentage
b.
109
c.
109.0909090909091
d.
109.0
Clear my choice
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following statements?

pi = int(3.14159)
print (pi)
Question 5Select one:
a.
3
b.
3.0
c.
3.14159
d.
0
Clear my choice
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following python commands produce:

x=1
y=2
if x == y:
print (x, "and", y, "are equal")
else:
if x < y:
print (x, "is less than", y)
else:
print (x, "is greater than", y)
Question 6Select one:
a.
1 and 2 are equal
b.
1 is less than 2
c.
1 is greater than 2
d.
2 is greater than 1
Clear my choice
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following statements?

pi = float(3.14159)
print (pi)
Question 7Select one:
a.
3
b.
3.0
c.
3.14159
d.
0
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
Expressions evaluate to either true or false. What will the output of the following code be when
the expression “Ni!” is evaluated?

if "Ni!":
print ('We are the Knights who say, "Ni!"')
else:
print ("Stop it! No more of this!")
Question 8Select one:
a.
Stop it!
b.
We are the Knights who say, "Ni!"
c.
Stop it! No more of this!"
d.
No output will be produced
Clear my choice
Question 9
Not yet answered
Marked out of 1.00
Flag question
Question text
Functions allow the programmer to encapsulate and generalize sections of code.
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
True/False: The % or modulus operator returns the remainder present when two integers do not
divide evenly into one another
Question 10Select one:
True
False
Self-Quiz Unit 4
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
A development approach that is intended to avoid a lot of debugging by only adding and testing
small amounts of code at a time is called.
Question 1Select one:
a.
structured development
b.
incremental development
c.
unit testing
d.
Systems development life cycle
Clear my choice
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python code below?
n = int(10.)
print(isinstance(n, float), isinstance(n * 1.0, float))
Question 2Select one:
a.
False
b.
True False
c.
True True
d.
False True
e.
False False
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
Boolean expressions control _________________
Question 3Select one:
a.
recursion
b.
conditional execution
c.
alternative execution
d.
all of the above
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
The modulus operator is the same as the divide operator.
Question 4Select one:
True
False
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
Encapsulation is the process of wrapping a piece of code in a function
Question 5Select one:
True
False
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following code produce?

def area(l, w):


temp = l * w;
return temp

l = 4.0
w = 3.25
x = area(l, w)
if ( x ):
print (x)
Question 6Select one:
a.
13.0
b.
0
c.
Expression does not evaluate to boolean true
d.
13
Clear my choice
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following statements produce using Python IDLE in interactive mode?

>>> n = 2
>>> n += 5
>>> n
Question 7Select one:
a.
7
b.
5
c.
2
d.
an error message will occur
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
The int function can convert floating-point values to integers, and it performs rounding up/down
as needed.
Question 8Select one:
True
False
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
What will the output of this program be when it is executed?
def test_function( length, width, height):
print ("the area of the box is ", length*width*height)
return length*width*height

l = 12.5
w=5
h=2
test_function(l, w, h)

print ("The area of the box is ", length*width*height)


Question 9Select one:
a.
A NameError because a variable not defined
b.
The area of the box is 125.0
c.
The area of the box is 0
d.
A SyntaxError due to illegal function call
Clear my choice
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
"Dead code" is code that performs calculations but never displays the results.
Question 10Select one:
True
False
Self-Quiz Unit 5
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
Python allows while loops inside while loops and if statements within the body of if statements.
Question 1Select one:
True
False
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following Python commands produce?

n = 10000
count = 0
while n:
count = count + 1
n = n // 10
print (count)
Question 2Select one:
a.
5
b.
0
c.
10000
d.
1000
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
The following Python code illustrates what programming concept?

bruce = 5
print (bruce,)
bruce = 7
print (bruce)
Question 3Select one:
a.
Reassignment
b.
Iteration
c.
Logical operators
d.
Conditionals
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
Repeated execution of a set of programming statements is called repetitive execution.
Question 4Select one:
True
False
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
The statements inside of a Python loop are known as the ____ of the loop.
Question 5Select one:
a.
body
b.
expression
c.
counter
d.
block
Clear my choice
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the value of the following Python expression?
"Xanadu" > "Yellowstone"
Question 6Select one:
True
False
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python method call below?
"bib".find('b', 1, 2)
Question 7Select one:
a.
0
b.
2
c.
-1
d.
syntax error
e.
3
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following statements produce using Python in interactive mode?

>>> n = 2
>>> n = n + 5
>>> n
Question 8Select one:
a.
7
b.
5
c.
2
d.
an error message will occur
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
An algorithm is a general process for solving a category of problems.
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
For the Python program below, will there be any output, and will the program terminate?
while True:
while 1 > 0:
break
print("Got it!")
break
Question 10Select one:
a.
Yes and no
b.
No and no
c.
Yes and yes
d.
No and yes
e.
Run-time error
Self-Quiz Unit 6
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
The elements of a list are immutable.
Question 1Select one:
True
False
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
The Python expression 'Unit 6'[-1] has value '6'.
Question 2Select one:
True
False
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
mylist = [ [2,4,1], [1,2,3], [2,3,5] ]
total = 0
for sublist in mylist:
total += sum(sublist)
print(total)
Question 3Select one:
a.
14
b.
23
c.
0
d.
13
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
fruit = "banana"
letter = fruit[1]
print (letter)
Question 4Select one:
a.
b
b.
a
c.
n
d.
banana
Clear my choice
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
To create a new object that has the same value as an existing object is knows as creating an alias.
Question 5Select one:
True
False
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
Traversal can only be accomplished with the "while" loop.
Question 6Select one:
True
False
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
index = "Ability is a poor man's wealth".find("W")
print(index)
Question 7Select one:
a.
24
b.
0
c.
23
d.
-1
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python code below?
my_list = [3, 2, 1]
print(my_list.sort())
Question 8Select one:
a.
0
b.
{1, 2, 3}
c.
None
d.
syntax error
e.
[1, 2, 3]
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
print(" ".join(mylist[1::2]))
Question 9Select one:
a.
now is the time
b.
now is the time for
c.
four score and seven years
d.
now four is score the and seven time years for
Clear my choice
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
String objects are modified with string slices.
Question 10Select one:
True
False
Self-Quiz Unit 7
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
What will the contents of mylist be after the following Python code has been executed?

>>> mylist = [1, 4, 2, 3]


>>> mylist.append(5)
Question 1Select one:
a.
[1, 4, 2, 3, 5]
b.
[5, 1, 4, 2, 3]
c.
[null]
d.
[1, 4, 2, 3]
Clear my choice
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following types are allowed for Python dictionary keys?
Question 2Select one:
a.
dictionary
b.
list
c.
list of dictionaries
d.
tuple
e.
All of the above
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
Assume that d is a Python dictionary. What does the following Python code produce?
result = dict()
for key in d:
val = d[key]
if val not in result:
result[val] = [key]
else:
result[val].append(key)
Question 3Select one:
a.
a histogram
b.
an inverted dictionary
c.
a list of tuples
d.
a lookup
e.
a reverse lookup
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
Python tuples are immutable.
Question 4Select one:
True
False
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
Assume that d is a Python dictionary. What does the following Python code produce?
d.items()

Question 5Select one:


a.
a histogram
b.
an inverted dictionary
c.
a list of tuples
d.
a lookup
e.
a reverse lookup
Clear my choice
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python code below?
my_list = [3, 2, 1]
print(my_list.sort())
Question 6Select one:
a.
0
b.
{1, 2, 3}
c.
None
d.
syntax error
e.
[1, 2, 3]
Clear my choice
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v.
Question 7Select one:
True
False
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following types are allowed for Python dictionary values?
Question 8Select one:
a.
dictionary
b.
list
c.
list of dictionaries
d.
tuple
e.
All of the above
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
Traversal can only be accomplished with the "while" loop.
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
Python dictionaries are mutable.
Question 10Select one:
True
False
Self-Quiz Unit 8
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output from the following interactive Python statement?
>>> '%g' % '0.1'

Question 1Select one:


a.
'0'
b.
'0.1'
c.
TypeError: float argument required, not str
d.
TypeError: not all arguments converted during string formatting
e.
TypeError: not enough arguments for format string
Clear my choice
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
Assume the following Python code has already executed.
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.isfile(cwd)

Question 2Select one:


a.
['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads']
b.
False
c.
True
d.
/Users/me
e.
/Users/me/Documents/file.txt
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output from the following interactive Python statement?
>>> '%g' % (0.1)
Question 3Select one:
a.
'0'
b.
'0.1'
c.
TypeError: float argument required, not str
d.
TypeError: not all arguments converted during string formatting
e.
TypeError: not enough arguments for format string
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
Assume the following Python code has already executed.
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.join(cwd, 'Documents/file.txt')

Question 4Select one:


a.
['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads']
b.
False
c.
True
d.
/Users/me
e.
/Users/me/Documents/file.txt
Clear my choice
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following Python statements runs without error?
Question 5Select one:
a.
open('three.txt').write(3)
b.
open('three.txt','w').write(3)
c.
open('three.txt','w').write(str(3))
d.
All of the above
e.
None of the above
Clear my choice
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
try:
fin = open('answer.txt')
fin.write('Yes')
except:
print('No')
print('Maybe')
Question 6Select one:
a.
Yes
b.
No
c.
Maybe
d.
Yes
Maybe
e.
No
Maybe
Clear my choice
Question 7
Not yet answered
Marked out of 1.00
Flag question
Question text
Assume the following Python code has already executed.
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.listdir(cwd)

Question 7Select one:


a.
['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads']
b.
False
c.
True
d.
/Users/me
e.
/Users/me/Documents/file.txt
Clear my choice
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python code below?
print('%d + %d + %d = %d' % (1, 2, 3, 1+2+3))
Question 8Select one:
a.
6
b.
(1 + 2 + 3 = 6)
c.
None
d.
1+2+3=6
e.
“1 + 2 + 3 = 6”
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
Handling an exception with a try statement is called throwing an exception.
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output from the following interactive Python statement?
>>> '%g %d' % (0.1)

Question 10Select one:


a.
'0'
b.
'0.1'
c.
TypeError: float argument required, not str
d.
TypeError: not all arguments converted during string formatting
e.
TypeError: not enough arguments for format string
Review Quiz
Back
Question 1
Not yet answered
Marked out of 1.00

Flag question
Question text
: The following code:

for fruit in ["banana", "apple", "quince"]:


print (fruit)

will produce the following output:

banana
apple
quince
Question 1Select one:
True
False
Question 2
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following Python 3 program produce?

x=5
if x % 2 == 0:
print (x)
else:
print (x, x%2)
Question 2Select one:
a.
5
b.
51
c.
2
d.
50
Clear my choice
Question 3
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following statements?

pi = int(3.14159)
print (pi)
Question 3Select one:
a.
3
b.
3.0
c.
3.14159
d.
0
Clear my choice
Question 4
Not yet answered
Marked out of 1.00

Flag question
Question text
Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities
beyond programming.
Question 4Select one:
True
False
Question 5
Not yet answered
Marked out of 1.00

Flag question
Question text
Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v.
Question 5Select one:
True
False
Question 6
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python statements?
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(1)

Question 6Select one:


a.
0
b.
1
c.
no output
d.
RuntimeError: maximum recursion depth exceeded
Clear my choice
Question 7
Not yet answered
Marked out of 1.00

Flag question
Question text
A variable that has a data type of "str" cannot be part of a compound data type
Question 7Select one:
True
False
Question 8
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following types are allowed for Python dictionary values?
Question 8Select one:
a.
dictionary
b.
list
c.
list of dictionaries
d.
tuple
e.
all of the above
Clear my choice
Question 9
Not yet answered
Marked out of 1.00

Flag question
Question text
The Python line below causes “5 dollars” to be printed.
print('%d %s' % (5, 'dollars'))
Question 9Select one:
True
False
Question 10
Not yet answered
Marked out of 1.00

Flag question
Question text
If you assign the result a void function to a variable in Python, you get:
Question 10Select one:
a.
an empty string
b.
the value -1
c.
the value 0
d.
the special value None
e.
an exception
Clear my choice
Question 11
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following python commands produce:

x=1
y=2
if x == y:
print (x, "and", y, "are equal")
else:
if x < y:
print (x, "is less than", y)
else:
print (x, "is greater than", y)
Question 11Select one:
a.
1 and 2 are equal
b.
1 is less than 2
c.
1 is greater than 2
d.
2 is greater than 1
Clear my choice
Question 12
Not yet answered
Marked out of 1.00

Flag question
Question text
Which of the following types are allowed for Python dictionary keys?
Question 12Select one:
a.
dictionary
b.
list
c.
list of dictionaries
d.
tuple
e.
All of the above
Clear my choice
Question 13
Not yet answered
Marked out of 1.00

Flag question
Question text
For the Python program below, will there be any output, and will the program terminate?
while True:
while 1 > 0:
break
print("Got it!")
break
Question 13Select one:
a.
Yes and no
b.
No and no
c.
Yes and yes
d.
No and yes
e.
Run-time error
Clear my choice
Question 14
Not yet answered
Marked out of 1.00

Flag question
Question text
Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What is line?

Question 14Select one:


a.
A file object
b.
A list of characters
c.
A list of words
d.
A string that may have a newline
e.
A string with no newline
Clear my choice
Question 15
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
mylist = [ [2,4,1], [1,2,3], [2,3,5] ]
total = 0
for sublist in mylist:
total += sum(sublist)
print(total)
Question 15Select one:
a.
14
b.
23
c.
0
d.
13
Clear my choice
Question 16
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following code produce?

print ("%s %d %f" % (5, 5, 5))


Question 16Select one:
a.
5 5 5.000000
b.
555
c.
5 5.000000
d.
0 5 5.0
Clear my choice
Question 17
Not yet answered
Marked out of 1.00

Flag question
Question text
Match concepts with their definition.

Answer 1 Question
17Choose...debuggingbugportabilityprogramnatural
An error in a program. languagetokenprint statementformal languagelow-level
languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 2 Question
The process of finding and 17Choose...debuggingbugportabilityprogramnatural
removing any of the three languagetokenprint statementformal languagelow-level
kinds of programming errors. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Any one of the languages that Answer 3 Question


people have designed for
specific purposes, such as 17Choose...debuggingbugportabilityprogramnatural
representing mathematical languagetokenprint statementformal languagelow-level
ideas or computer programs; languageinterpreterparseproblem solvingscripthigh-level
all programming languages languagesyntax
are this kind of languages.

Answer 4 Question
A programming language like
17Choose...debuggingbugportabilityprogramnatural
Python that is designed to be
languagetokenprint statementformal languagelow-level
easy for humans to read and
languageinterpreterparseproblem solvingscripthigh-level
write.
languagesyntax

Answer 5 Question
17Choose...debuggingbugportabilityprogramnatural
A program that reads another
languagetokenprint statementformal languagelow-level
program and executes it.
languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

A programming language that Answer 6 Question


is designed to be easy for a 17Choose...debuggingbugportabilityprogramnatural
computer to execute; also languagetokenprint statementformal languagelow-level
called machine language or languageinterpreterparseproblem solvingscripthigh-level
assembly language. languagesyntax

Answer 7 Question
Any one of the languages that 17Choose...debuggingbugportabilityprogramnatural
people speak that evolved languagetokenprint statementformal languagelow-level
naturally. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 8 Question
To examine a program and 17Choose...debuggingbugportabilityprogramnatural
analyse the syntactic languagetokenprint statementformal languagelow-level
structure. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 9 Question
A property of a program that 17Choose...debuggingbugportabilityprogramnatural
can run on more than one kind languagetokenprint statementformal languagelow-level
of computer. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax
Answer 10 Question
An instruction that causes the 17Choose...debuggingbugportabilityprogramnatural
Python interpreter to display a languagetokenprint statementformal languagelow-level
value on the screen. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 11 Question
The process of formulating a 17Choose...debuggingbugportabilityprogramnatural
problem, finding a solution, languagetokenprint statementformal languagelow-level
and expressing the solution. languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 12 Question
a sequence of instructions that
17Choose...debuggingbugportabilityprogramnatural
specifies to a computer
languagetokenprint statementformal languagelow-level
actions and computations to
languageinterpreterparseproblem solvingscripthigh-level
be performed.
languagesyntax

Answer 13 Question
A program stored in a file 17Choose...debuggingbugportabilityprogramnatural
(usually one that will be languagetokenprint statementformal languagelow-level
interpreted). languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Answer 14 Question
One of the basic elements of
17Choose...debuggingbugportabilityprogramnatural
the syntactic structure of a
languagetokenprint statementformal languagelow-level
program, analogous to a word
languageinterpreterparseproblem solvingscripthigh-level
in a natural language.
languagesyntax

Answer 15 Question
17Choose...debuggingbugportabilityprogramnatural
The structure of a program. languagetokenprint statementformal languagelow-level
languageinterpreterparseproblem solvingscripthigh-level
languagesyntax

Question 18
Not yet answered
Marked out of 1.00

Flag question
Question text
If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary.
Question 18Select one:
a.
values and keys
b.
indices
c.
keys and values
d.
values
e.
keys
Clear my choice
Question 19
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following python commands produce:

n = 10000
count = 0
while n:
count = count + 1
n = n // 10

print (count)
Question 19Select one:
a.
5
b.
0
c.
10000
d.
1000
Clear my choice
Question 20
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the value of the following Python expression?
not(True and False)

Question 20Select one:


True
False
Question 21
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the following Python program?
try:
fin = open('answer.txt')
fin.write('Yes')
except:
print('No')
print('Maybe')
Question 21Select one:
a.
Yes
b.
No
c.
Maybe
d.
Yes
Maybe
e.
No
Maybe
Clear my choice
Question 22
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following code produce?

def area(l, w):


temp = l * w;
return temp
l = 4.0
w = 3.25
x = area(l, w)
if ( x ):
print (x)
Question 22Select one:
a.
13.0
b.
0
c.
Expression does not evaluate to boolean true
d.
13
Clear my choice
Question 23
Not yet answered
Marked out of 1.00

Flag question
Question text
Which one of the following Python expressions has the value 10?
Question 23Select one:
a.
8^2
b.
8 ** 2
c.
8 +- 2
d.
8 += 2
e.
8 -+ 2
Clear my choice
Question 24
Not yet answered
Marked out of 1.00

Flag question
Question text
What output will the following code produce?

mylist = [ [2,4,1], [1,2,3], [2,3,5] ]


a=0
b=0
total = 0
while a <= 2:
while b < 2:
total += mylist[a][b]
b += 1
a += 1
b=0
print (total)
Question 24Select one:
a.
14
b.
23
c.
0
d.
13
Clear my choice
Question 25
Not yet answered
Marked out of 1.00

Flag question
Question text
What is Python’s response to the command: type(0.123)
Question 25Select one:
a.
<class 'float'>
b.
<class 'bool'>
c.
SyntaxError: invalid syntax
d.
<class 'int'>
e.
<class 'str'>
Clear my choice
Question 26
Not yet answered
Marked out of 1.00

Flag question
Question text
Given the following code, what will the output be?

mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
a=0
while a < 7:
print (mylist[a],)
a += 2
Question 26Select one:
a.
now is the time
b.
now is the time for
c.
for score and seven years
d.
now four is score the and seven time years for
Clear my choice
Question 27
Not yet answered
Marked out of 1.00

Flag question
Question text
What is the output of the Python code below?
my_list = [3, 2, 1]
print(my_list.sort())
Question 27Select one:
a.
0
b.
{1, 2, 3}
c.
None
d.
syntax error
e.
[1, 2, 3]
Clear my choice
Question 28
Not yet answered
Marked out of 1.00

Flag question
Question text
Which one of the following Python expressions generates a syntax error?
Question 28Select one:
a.
8^2
b.
8 ** 2
c.
8 +- 2
d.
8 += 2
e.
8 -+ 2
Clear my choice
Question 29
Not yet answered
Marked out of 1.00

Flag question
Question text
Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What is word?

Question 29Select one:


a.
A file object
b.
A list of characters
c.
A list of words
d.
A string that may have a newline
e.
A string with no newline
Clear my choice
Question 30
Not yet answered
Marked out of 1.00

Flag question
Question text
Handling an exception with a try statement is called throwing an exception.
Question 30Select one:
True
False

You might also like