Professional Documents
Culture Documents
Select one:
b. <class 'bool'>
d. <class 'int'>
e. <class 'str'>
Question 2 Correct Mark 1.00 out of 1.00
>>> print(2 + 2)
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
What does the Python interpreter output for the following input?
>>> 1,234.567,890
Select one:
a. 1234
b. 1234.6
c. 1234.56789
Question 4 Correct Mark 1.00 out of 1.00
Select one:
a. 8 ^ 2
b. 8 ** 2
c. 8 +- 2
d. 8 += 2
e. 8 -+ 2
>>> print(2 + 2)
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
Question 6 Correct Mark 1.00 out of 1.00
Select one:
b. <class 'bool'>
d. <class 'int'>
e. <class 'str'>
Select one:
a. ambiguity
b. literalness
c. poetry
d. prose
e. redundancy
Question 8 Correct Mark 1.00 out of 1.00
Select one:
a. 123
b. 0123
c. 0.00
d. 12.3
e. 0.75
Which one of the following Python expressions computes the total number of seconds in 21
minutes and 21 seconds?
Select one:
a. 21 + 21
b. 21 + 60
d. 21 * 60 + 21
Question 10 Correct Mark 1.00 out of 1.00
Programming languages are ______ languages that have been designed to express computations.
Select one:
a. informal
b. mathematical
c. formal
d. natural
e. logical
Jump to...
Raymond Enokela
Which one of the following Python expressions computes the number of miles in 5 km, where one
mile is 1.61 km?
Select one:
a. 5 * 1.61
b. 5 / 1.61
c. 1.61 / 5
d. 1.61 + 5
Select one:
b. <class 'bool'>
d. <class 'int'>
e. <class 'str'>
Select one:
True
False
>>> print(2 + 2)
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
>>> print(2 + 2)
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
>>> print(2 + 2)
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
Which one of the following Python expressions has the value 64?
Select one:
a. 8 ^ 2
b. 8 ** 2
c. 8 +- 2
d. 8 += 2
e. 8 -+ 2
Select one:
True
False
Which one of the following Python expressions has the value 10?
Select one:
a. 8 ^ 2
b. 8 ** 2
c. 8 +- 2
d. 8 += 2
e. 8 -+ 2
True or False: Learning to debug can be frustrating, but it is a valuable skill that is useful for many
activities beyond programming.
Select one:
True
False
Jump to...
Learning Guide Unit 2 →
Raymond Enokela
pi = oat(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
expression
A statement that creates a new variable and gives it a value.
Information in a program that is meant for other programmers (or anyone concatenate
reading the source code) and has no e ect on the execution of the program.
concatenate
To join two operands end-to-end.
concatenate
What the Python interpreter does to an expression to nd its value.
result value.
operand
A Python data type that stores oating-point numbers.
operand
A Python data type that holds positive and negative whole numbers.
concatenate
A reserved word that is used by the interpreter to parse programs.
evaluate
One of the values on which an operator operates.
evaluate
A unit of code that the Python interpreter can execute.
comment
A Python data type that holds a string of characters.
expression.
operand
A name that refers to a value.
The correct answer is: A statement that creates a new variable and gives it a value. → assignment
statement, Information in a program that is meant for other programmers (or anyone reading the source
code) and has no e ect on the execution of the program. → comment, The ability to combine simple
expressions and statements into compound statements and expressions in order to represent complex
computations concisely. → composition, To join two operands end-to-end. → concatenate, What the Python
interpreter does to an expression to nd its value. → evaluate, A combination of variables, operators, and
values that represents a single result value. → expression, A Python data type that stores oating-point
numbers. → oat, A Python data type that holds positive and negative whole numbers. → int, A reserved
word that is used by the interpreter to parse programs. → keyword, One of the values on which an operator
operates. → operand, A special symbol that represents a simple computation like addition, multiplication,
or string concatenation. → operator, A unit of code that the Python interpreter can execute. → statement, A
Python data type that holds a string of characters. → str, A number or letter that can be stored in a variable
or evaluated in an expression. → value, A name that refers to a value. → variable
Select one:
True
False
Select one:
True
False
In Python, the ‘+’ operator can be used with numbers and with strings. What is a property that
number addition has, but string concatenation does not?
Select one:
c. expression value does not depend on the order of numeric addition operands
The correct answer is: expression value does not depend on the order of numeric addition operands
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.
Select one:
True
False
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():
def f2():
def f3():
print(f3())
Select one:
a. ababababababababab
b. abababababab
c. abababab
d. ababab
e. ababababab
Select one:
a. 1,000
b. 1,000,000
c. (1, 0, 0)
Select one:
True
False
In a script, an expression all by itself is a legal statement, but it does not do anything.
Select one:
True
False
Jump to...
>>> n = 17
>>> print (n)
Select one:
a. (n)
b. 17.0
c. n
d. 17
Select one:
True
False
Question 3 Incorrect Mark 0.00 out of 1.00
What is the output of the Python code below when run in script mode?
y=3
x=5
x+y
“x + y”
Select one:
a. 8
b. x + y
c. no output
d. run-time error
e. compile error
Python functions may or may not take arguments and may or may not return a result.
Select one:
True
False
Question 5 Correct Mark 1.00 out of 1.00
Select one:
a. runtime error
b. compile error
c. syntax error
d. semantic error
Select one:
a. 6
b. 5
c. 4
d. 3
Question 7 Incorrect Mark 0.00 out of 1.00
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
When a Python function is called, inside the function, the arguments are assigned to variables
called parameters.
Select one:
True
False
Select one:
a. a = b = 123
b. ‘3’ = 3
c. x = int(“123”)
d. y = None
e. z = “hi” * 10
Programmers generally choose names for their variables that are meaningful and document what
the variable is used for.
Select one:
True
False
Jump to...
Raymond Enokela
Select one:
a. 6
b. 5
c. 4
d. 3
Select one:
True
False
When de ning a Python function that has no parameters, the parentheses that follow the
function’s name are optional.
Select one:
True
False
As programs get bigger and more complicated, they get more di cult to read. This is one reason
why programmers should use comments in their code.
Select one:
True
False
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
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)?
Select one:
a. argument
b. return value
c. method
e. global variable
A property of a program that can run on more than one kind of computer is called portability.
Select one:
True
False
Select one:
a. 16
b. 8
c. 4
d. 2
Select one:
a. a syntax error
b. an exception
c. a compilation error
d. a semantic error
e. a late error
Select one:
True
False
Jump to...
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)
Select one:
b. 1 is less than 2
c. 1 is greater than 2
d. 2 is greater than 1
Question 2 Not answered Marked out of 1.00
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(0)
Select one:
a. 0
b. 1
c. no output
Select one:
True
False
Question 4 Not answered Marked out of 1.00
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
Question 6 Not answered Marked out of 1.00
True/False: The % or modulus operator returns the remainder present when two integers do not
divide evenly into one another
Select one:
True
False
Occasionally, it is useful to have a body of an if statement that does nothing. In that case, you
can use the following statement:
Select one:
a. # do nothing
b. 0 = 0
c. Null
d. pass
e. Void
Question 8 Not answered Marked out of 1.00
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(1)
Select one:
a. 0
b. 1
c. no output
x=5
if x % 2 == 1:
else:
Select one:
a. 5
b. (5, 1)
c. 2
d. (5, 0)
Question 10 Not answered Marked out of 1.00
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!")
Select one:
a. Stop it!
The correct answer is: We are the Knights who say, "Ni!"
Jump to...
Raymond Enokela
x=5
if x % 2 == 0:
print (x)
else:
print (x, x%2)
Select one:
a. 5
b. 5 1
c. 2
d. 5 0
The order in which statements are executed during a program run. Choose...
The rst part of a compound statement, begins with a keyword and ends with a
Choose...
colon ( : )
A statement that executes a function. It consists of the name of the function
Choose...
followed by a list of arguments enclosed in parentheses.
A variable de ned inside a function that can only be used inside its function. Choose...
The correct answer is: The order in which statements are executed during a program run. → ow of
execution, The rst part of a compound statement, begins with a keyword and ends with a colon ( : ) →
header, A statement that executes a function. It consists of the name of the function followed by a list of
arguments enclosed in parentheses. → function call, A variable de ned inside a function that can only be
used inside its function. → local variable, A graphical representation of functions, their variables, and the
values to which they refer. → stack diagram
pi = oat(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
percentage = ( 60 * 100) // 55
print (percentage)
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
Select one:
a. 3
b. 2
c. in nite number
d. 1
e. not de ned
Select one:
True
False
If you assign the result a void function to a variable in Python, you get:
Select one:
a. an empty string
b. the value -1
c. the value 0
e. an exception
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)
Select one:
b. 1 is less than 2
c. 1 is greater than 2
d. 2 is greater than 1
True/False: The % or modulus operator returns the remainder present when two integers do not
divide evenly into one another
Select one:
True
False
Jump to...
If you assign the result a void function to a variable in Python, you get:
Select one:
a. an empty string
b. the value -1
c. the value 0
e. an exception
pi = oat(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(0)
Select one:
a. 0
b. 1
c. no output
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
The order in which statements are executed during a program run. Choose...
The rst part of a compound statement, begins with a keyword and ends with a
Choose...
colon ( : )
A statement that executes a function. It consists of the name of the function
Choose...
followed by a list of arguments enclosed in parentheses.
A variable de ned inside a function that can only be used inside its function. Choose...
The correct answer is: The order in which statements are executed during a program run. → ow of
execution, The rst part of a compound statement, begins with a keyword and ends with a colon ( : ) →
header, A statement that executes a function. It consists of the name of the function followed by a list of
arguments enclosed in parentheses. → function call, A variable de ned inside a function that can only be
used inside its function. → local variable, A graphical representation of functions, their variables, and the
values to which they refer. → stack diagram
Question 6 Not answered Marked out of 1.00
x=5
if x % 2 == 0:
print (x)
else:
print (x, x%2)
Select one:
a. 5
b. 5 1
c. 2
d. 5 0
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
Occasionally, it is useful to have a body of an if statement that does nothing. In that case, you
can use the following statement:
Select one:
a. # do nothing
b. 0 = 0
c. Null
d. pass
e. Void
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!")
Select one:
a. Stop it!
The correct answer is: We are the Knights who say, "Ni!"
Question 10 Not answered Marked out of 1.00
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0
Jump to...
Python functions may or may not take arguments and may or may not return a result.
Select one:
True
False
If you assign the result of calling a void function to a variable in Python, you get:
Select one:
a. an empty string
b. the value -1
c. the value 0
e. an exception
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)?
Select one:
a. argument
b. return value
c. method
e. global variable
>>> print(2 + 2)
4
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
Select one:
a. 6
b. 5
c. 4
d. 3
def recurse(a):
if (a == 1):
print(a)
else:
recurse(a)
recurse(1)
Select one:
a. 0
b. 1
c. no output
percentage = ( 60 * 100) // 55
print (percentage)
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
>>> n = 17
>>> print (n)
Select one:
a. 0
b. 17.0
c. n
d. 17
Select one:
a. runtime error
b. compile error
c. syntax error
d. semantic error
Select one:
True
False
Select one:
a. 2 ^ 2
b. 2 ** 2
c. 2 +- 2
d. 2 += 2
e. 2 -+ 2
Select one:
a. 16
b. 8
c. 4
d. 2
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0
>>> print(2 + 2)
4
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value
Select one:
a. a = b = 123
b. ‘3’ = 3
c. x = int(“123”)
d. y = None
e. z = “hi” * 10
The % or modulus operator returns the remainder from dividing two numbers.
Select one:
True
False
In Python, the ‘+’ operator can be used with numbers and with strings. What is a property that
number addition has, but string concatenation does not?
Select one:
c. The expression value does not depend on the order of numeric addition operands.
The correct answer is: The expression value does not depend on the order of numeric addition operands.
Question 18 Correct Mark 1.00 out of 1.00
x=2
y=1
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)
Select one:
b. 1 is less than 2
c. 1 is greater than 2
d. 2 is greater than 1
Any one of the languages that people have designed for speci c purposes, such as
formal language
representing mathematical ideas or computer programs; all programming
languages are this kind of languages.
natural language
Any one of the languages that people speak that evolved naturally.
An error that does not occur until the program has started to execute but that syntax
An error in a program that makes it do something other than what the semantics
programmer intended.
formal language
The meaning of a program.
semantics
The structure of a program.
An error in a program that makes it impossible to parse — and therefore runtime error
impossible to interpret.
One of the basic elements of the syntactic structure of a program, analogous to a syntax
The correct answer is: Any one of the languages that people have designed for speci c purposes, such as
representing mathematical ideas or computer programs; all programming languages are this kind of
languages. → formal language, Any one of the languages that people speak that evolved naturally. →
natural language, An error that does not occur until the program has started to execute but that prevents
the program from continuing. → runtime error, An error in a program that makes it do something other
than what the programmer intended. → semantic error, The meaning of a program. → semantics, The
structure of a program. → syntax, An error in a program that makes it impossible to parse — and therefore
impossible to interpret. → syntax error, One of the basic elements of the syntactic structure of a program,
analogous to a word in a natural language. → token
Question 20 Correct Mark 1.00 out of 1.00
concatenate
To join two operands end-to-end.
evaluate
What the Python interpreter does to an expression to nd its value.
expression
A combination of variables, operators, and values that represents a single result value.
keyword
A reserved word that is used by the interpreter to parse programs.
A special symbol that represents a simple computation like addition, multiplication, or operator
string concatenation.
statement
A unit of code that the Python interpreter can execute.
variable
A name that refers to a value.
The correct answer is: To join two operands end-to-end. → concatenate, What the Python interpreter does
to an expression to nd its value. → evaluate, A combination of variables, operators, and values that
represents a single result value. → expression, A reserved word that is used by the interpreter to parse
programs. → keyword, A special symbol that represents a simple computation like addition, multiplication,
or string concatenation. → operator, A unit of code that the Python interpreter can execute. → statement, A
name that refers to a value. → variable
← Self-Quiz Unit 3
Jump to...
Python allows while loops inside while loops and if statements within the body of if statements.
Select one:
True
False
A Python loop where the terminating condition is never achieved is called _______.
Select one:
a. an in nite loop
b. a universal loop
c. a while loop
The statements inside of a Python loop are known as the ____ of the loop.
Select one:
a. body
b. expression
c. counter
d. block
n = 10000
count = 0
while n:
count = count + 1
n = n // 10
print (count)
Select one:
a. 5
b. 0
c. 10000
d. 1000
def subroutine( n ):
while n > 0:
print (n,)
n=n-1
Select one:
The correct answer is: Counts from n down to 1 and displays each number
Select one:
True
False
For the Python program below, will there be any output, and will the program terminate?
while True:
break
break
Select one:
a. Yes and no
b. No and no
d. No and yes
e. Run-time error
What output will the following statements produce using Python in interactive mode?
>>> n = 2
>>> n = n + 5
>>> n
Select one:
a. 7
b. 5
c. 2
A Python string is a sequence of characters. You can access the string characters with the _______.
Select one:
a. () operator
b. % operator
c. dot operator
d. // operator
e. [] operator
bruce = 5
print (bruce,)
bruce = 7
print (bruce)
Select one:
a. Reassignment
b. Iteration
c. Logical operators
d. Conditionals
Jump to...
"bib". nd('b', 1, 2)
Select one:
a. 0
b. 2
c. -1
d. syntax error
e. 3
Select one:
True
False
The following Python code succeeds in modifying the rst character of the string to “Y”.
fred = "Hello"
fred[0] = "Y"
Select one:
True
False
n = 10
while n != 1:
print (n,)
if n % 2 == 0: # n is even
n = n // 2
else: # n is odd
n=n*3+1
Select one:
a. 10 5 16 8 4 2
c. 8 4 2
d. 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2
Question 5 Correct Mark 1.00 out of 1.00
Select one:
True
False
Select one:
True
False
A Python string is a sequence of characters. You can access the string characters with the _______.
Select one:
a. () operator
b. % operator
c. dot operator
d. // operator
e. [] operator
Question 8 Correct Mark 1.00 out of 1.00
def subroutine( n ):
while n > 0:
print (n,)
n=n-1
Select one:
The correct answer is: Counts from n down to 1 and displays each number
Python allows while loops inside while loops and if statements within the body of if statements.
Select one:
True
False
Question 10 Correct Mark 1.00 out of 1.00
bruce = 5
print (bruce,)
bruce = 7
print (bruce)
Select one:
a. Reassignment
b. Iteration
c. Logical operators
d. Conditionals
Jump to...
Raymond Enokela
Select one:
True
False
A Python loop where the terminating condition is never achieved is called _______.
Select one:
a. an in nite loop
b. a universal loop
c. a while loop
"bib". nd('b', 1, 2)
Select one:
a. 0
b. 2
c. -1
d. syntax error
e. 3
For the Python program below, will there be any output, and will the program terminate?
while True:
break
break
Select one:
a. Yes and no
b. No and no
d. No and yes
e. Run-time error
n = 10000
count = 0
while n:
count = count + 1
n = n // 10
print (count)
Select one:
a. 5
b. 0
c. 10000
d. 1000
n = 10
while n != 1:
print (n,)
if n % 2 == 0: # n is even
n = n // 2
else: # n is odd
n=n*3+1
Select one:
a. 10 5 16 8 4 2
c. 8 4 2
d. 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2
The following Python code succeeds in modifying the rst character of the string to “Y”.
fred = "Hello"
fred[0] = "Y"
Select one:
True
False
Select one:
True
False
What output will the following statements produce using Python in interactive mode?
>>> n = 2
>>> n = n + 5
>>> n
Select one:
a. 7
b. 5
c. 2
The statements inside of a Python loop are known as the ____ of the loop.
Select one:
a. body
b. expression
c. counter
d. block
Jump to...
Select one:
True
False
Select one:
a. 24
b. 0
c. 23
d. -1
Question 3 Correct Mark 1.00 out of 1.00
fruit = "banana"
letter = fruit[1]
print (letter)
Select one:
a. b
b. a
c. n
d. banana
Select one:
True
False
Question 5 Correct Mark 1.00 out of 1.00
Select one:
a. 14
b. 23
c. 0
d. 13
A variable that has a data type of "str" cannot be part of a compound data type
Select one:
True
False
Question 7 Correct Mark 1.00 out of 1.00
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
a=0
while a < 8:
print(mylist[a],)
a=a+2
Select one:
Select one:
True
False
Select one:
True
False
Question 10 Correct Mark 1.00 out of 1.00
my_list = [3, 2, 1]
print(my_list.sort())
Select one:
a. 0
b. {1, 2, 3}
c. None
d. syntax error
e. [1, 2, 3]
Jump to...
Raymond Enokela
Select one:
True
False
To create a new object that has the same value as an existing object is knows as creating an alias.
Select one:
True
False
Select one:
a. 24
b. 0
c. 23
d. -1
Select one:
a. 14
b. 23
c. 0
d. 13
Select one:
True
False
my_list = [3, 2, 1]
print(my_list)
Select one:
a. 0
b. {3, 2, 1}
c. None
d. syntax error
e. [3, 2, 1]
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
print(" ".join(mylist[1::2]))
Select one:
Select one:
True
False
A variable that has a data type of "str" cannot be part of a compound data type
Select one:
True
False
Select one:
a. 24
b. 0
c. 23
d. -1
Jump to...
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
a=0
while a < 8:
print(mylist[a],)
a=a+2
Select one:
Select one:
a. 14
b. 23
c. 0
d. 13
Select one:
True
False
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
print(" ".join(mylist[1::2]))
Select one:
my_list = [3, 2, 1]
print(my_list.sort())
Select one:
a. 0
b. {1, 2, 3}
c. None
d. syntax error
e. [1, 2, 3]
Select one:
True
False
my_list = [3, 2, 1]
print(my_list)
Select one:
a. 0
b. {3, 2, 1}
c. None
d. syntax error
e. [3, 2, 1]
Select one:
a. 24
b. 0
c. 23
d. -1
Select one:
True
False
fruit = "banana"
letter = fruit[1]
print (letter)
Select one:
a. b
b. a
c. n
d. banana
Jump to...
Which of the following types are allowed for Python dictionary values?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple
/
Question 2 Incorrect Mark 0.00 out of 1.00
Which of the following types are allowed for Python dictionary keys?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple
Select one:
a. 0
b. 1
c. False
d. True
e. syntax error
/
Question 4 Incorrect Mark 0.00 out of 1.00
What will the contents of mylist be after the following Python code has been
executed?
Select one:
a. [1, 4, 2, 3, 5]
b. [5, 1, 4, 2, 3]
c. [null]
d. [1, 4, 2, 3]
In the following segment of Python code, what do we call the portion of the
statement that follows the dot('.capitalize')?
str.capitalize('maryland')
Select one:
a. Module
b. Method
c. Attribute
d. Function name
/
Question 6 Correct Mark 1.00 out of 1.00
Assume that d is a Python dictionary. What does the following Python code produce?
for k in d:
if d[k] == v:
return k
Select one:
a. a histogram
b. an inverted dictionary
c. a list of tuples
d. a lookup
e. a reverse lookup
my_tup = (3, 2, 1, 2)
print(tuple(sorted(my_tup)))
Select one:
a. (1, 2, 3)
b. {1, 2, 2, 3}
c. (1, 2, 2, 3)
d. syntax error
e. [1, 2, 2, 3]
/
Question 8 Correct Mark 1.00 out of 1.00
Assume that d is a Python dictionary. What does the following Python code produce?
d.items()
Select one:
a. a histogram
b. an inverted dictionary
c. a list of tuples
d. a lookup
e. a reverse lookup
Select one:
True
False
/
Question 10 Correct Mark 1.00 out of 1.00
Select one:
True
False
Jump to...
/
1
Raymond Enokela
my_tup = (3, 2, 1, 2)
print(tuple(sorted(my_tup)))
Select one:
a. (1, 2, 3)
b. {1, 2, 2, 3}
c. (1, 2, 2, 3)
d. syntax error
e. [1, 2, 2, 3]
/
Question 2 Correct Mark 1.00 out of 1.00
Select one:
True
False
print(dict().get("no", "help!"))
Select one:
a. True
b. no
c. no help!
d. help!
e. False
/
Question 4 Correct Mark 1.00 out of 1.00
Select one:
True
False
If you use a Python dictionary in a for statement, it traverses the _____ of the
dictionary.
Select one:
b. indices
d. values
e. keys
/
Question 6 Correct Mark 1.00 out of 1.00
Assume that d is a Python dictionary. What does the following Python code produce?
d.items()
Select one:
a. a histogram
b. an inverted dictionary
c. a list of tuples
d. a lookup
e. a reverse lookup
Which of the following types are allowed for Python dictionary values?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple
/
Question 8 Incorrect Mark 0.00 out of 1.00
What will the contents of mylist be after the following Python code has been
executed?
Select one:
a. [1, 4, 2, 3, 5]
b. [5, 1, 4, 2, 3]
c. [null]
d. [1, 4, 2, 3]
my_list = [3, 2, 1]
print(my_list.sort())
Select one:
a. 0
b. {1, 2, 3}
c. None
d. syntax error
e. [1, 2, 3]
/
Question 10 Correct Mark 1.00 out of 1.00
Select one:
True
False
Jump to...
/
1
Raymond Enokela
Which of the following types are allowed for Python dictionary keys?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple
/
Question 2 Incorrect Mark 0.00 out of 1.00
Assume that d is a Python dictionary. What does the following Python code produce?
for k in d:
if d[k] == v:
return k
Select one:
a. a histogram
b. an inverted dictionary
c. a list of tuples
d. a lookup
e. a reverse lookup
/
Question 3 Incorrect Mark 0.00 out of 1.00
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)
Select one:
a. a histogram
b. an inverted dictionary
c. a list of tuples
d. a lookup
e. a reverse lookup
Select one:
True
False
/
Question 5 Incorrect Mark 0.00 out of 1.00
Select one:
a. 0
b. 1
c. False
d. True
e. syntax error
Select one:
True
False
/
Question 7 Incorrect Mark 0.00 out of 1.00
In the following segment of Python code, what do we call the portion of the
statement that follows the dot('.capitalize')?
str.capitalize('maryland')
Select one:
a. Module
b. Method
c. Attribute
d. Function name
Select one:
True
False
/
Question 9 Not answered Marked out of 1.00
print(dict().get("no", "help!"))
Select one:
a. True
b. no
c. no help!
d. help!
e. False
If you use a Python dictionary in a for statement, it traverses the _____ of the
dictionary.
Select one:
b. indices
d. values
e. keys
Jump to...
/
Learning Guide Unit 8 ►
/
1
Raymond Enokela
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.is le(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
/
Question 2 Correct Mark 1.00 out of 1.00
try:
n = open('answer.txt')
n.write('Yes')
except:
print('No')
print('Maybe')
Select one:
a. Yes
b. No
c. Maybe
d. Yes
Maybe
e. No
Maybe
/
Question 3 Correct Mark 1.00 out of 1.00
Select one:
a. '0'
b. '0.1'
/
Question 4 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
What is word?
Select one:
a. A le object
b. A list of characters
c. A list of words
/
Question 5 Correct Mark 1.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.abspath(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
/
Question 6 Correct Mark 1.00 out of 1.00
Select one:
a. 6
b. (1 + 2 + 3 = 6)
c. None
d. 1 + 2 + 3 = 6
e. “1 + 2 + 3 = 6”
Select one:
a. open('three.txt').write(3)
b. open('three.txt','w').write(3)
c. open('three.txt','w').write(str(3))
/
Question 8 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
Select one:
a. Lines in a le
b. Lines in a list
c. Words in a dictionary
d. Words in a list
e. Words in a string
/
Question 9 Correct Mark 1.00 out of 1.00
Select one:
a. '0'
b. '0.1'
The correct answer is: TypeError: not all arguments converted during string formatting
Select one:
True
False
Jump to...
/
1
Raymond Enokela
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.isdir(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
/
Question 2 Correct Mark 1.00 out of 1.00
Select one:
a. '0'
b. '0.1'
The correct answer is: TypeError: not enough arguments for format string
/
Question 3 Incorrect Mark 0.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
/
Question 4 Correct Mark 1.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
What is n?
Select one:
a. A le object
b. A list of characters
c. A list of words
Select one:
/
Question 6 Incorrect Mark 0.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.listdir(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
The correct answer is: ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads']
/
Question 7 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
What is line?
Select one:
a. A le object
b. A list of characters
c. A list of words
/
Question 8 Incorrect Mark 0.00 out of 1.00
Select one:
a. '0'
b. '0.1'
Select one:
a. '0'
b. '0.1'
The correct answer is: TypeError: oat argument required, not str
/
Question 10 Correct Mark 1.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.exists(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
Jump to...
/
1
Raymond Enokela
Select one:
a. '0'
b. '0.1'
/
Question 2 Correct Mark 1.00 out of 1.00
Select one:
a. 6
b. (1 + 2 + 3 = 6)
c. None
d. 1 + 2 + 3 = 6
e. “1 + 2 + 3 = 6”
/
Question 3 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
What is word?
Select one:
a. A le object
b. A list of characters
c. A list of words
/
Question 4 Correct Mark 1.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
Select one:
a. open('three.txt').write(3)
b. open('three.txt','w').write(3)
c. open('three.txt','w').write(str(3))
/
Question 6 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
Select one:
a. Lines in a le
b. Lines in a list
c. Words in a dictionary
d. Words in a list
e. Words in a string
/
Question 7 Correct Mark 1.00 out of 1.00
Select one:
a. '0'
b. '0.1'
The correct answer is: TypeError: not all arguments converted during string formatting
/
Question 8 Incorrect Mark 0.00 out of 1.00
import os
cwd = os.getcwd()
Which answer is most likely output from the following Python statement?
os.path.abspath(cwd)
Select one:
b. False
c. True
d. /Users/me
e. /Users/me/Documents/ le.txt
/
Question 9 Incorrect Mark 0.00 out of 1.00
n = open('words.txt')
for line in n:
word = line.strip()
print(word)
What is n?
Select one:
a. A le object
b. A list of characters
c. A list of words
/
Question 10 Correct Mark 1.00 out of 1.00
Select one:
a. '0'
b. '0.1'
The correct answer is: TypeError: not enough arguments for format string
Jump to...