CS 1101

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!
b.

We are the Knights who say, "Ni!

How many different values can a Boolean expression have?
Select one:
a. 3
b. 2 Correct
c. infinite number
d. 1
e. not defined

2

True/False: The % or modulus operator returns the remainder present when two integers do not divide evenly into one another
Select one:
True Correct
False

True

One way to generalize a function is to replace a variable with a value.
Select one:
True Incorrect
False

False

The order in which statements are executed during a program run. ? flow of execution, The first 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

The order in which statements are executed during a program run. ? flow of execution, The first 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

What is the output of the following statements?
pi = float(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159 Correct
d. 0

3.14159

What is the output of the following Python statements?
percentage = ( 60 * 100) // 55
print (percentage)
Select one:
a. percentage
b. 109 Correct
c. 109.0909090909091
d. 109.0

109

What is the output of the following Python statements?
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(0)
Select one:
a. 0 Correct
b. 1
c. no output
d. RuntimeError: maximum recursion depth exceeded

0

What is the output of the following Python statements?
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(1)
Select one:
a. 0
b. 1
c. no output
d. RuntimeError: maximum recursion depth exceeded Correct

RuntimeError: maximum recursion depth exceeded

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)
Select one:
a. 1 and 2 are equal
b. 1 is less than 2 Correct
c.

1 is less than 2

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
d. the special value None
e. an exception

the special value None

What is the output of the following Python statements?
x = 5
if x % 2 == 1:
print (x)
else:
print (x, x%2)
Select one:
a. 5
b. (5, 1)
c. 2
d. (5, 0)

5

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

pass

What is the output of the following Python statements?
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0

3

Functions allow the programmer to encapsulate and generalize sections of code.
Select one:
True
False

True

What is the output of the following statements?
pi = int(3.14159)
print (pi)
Select one:
a. 3
b. 3.0
c. 3.14159
d. 0

3

What output will the following python command produce:
>>> percentage = float ( 60 * 100) / 55
>>> print (percentage)
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0

109.0909090909091

What output will the following python commands produce:
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

5 1

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!
b.

Ni!

As programs get bigger and more complicated, they get more difficult to read. This is one reason why programmers should use comments in their code.
Select one:
True Correct
False

True

In Python, the expression "a *
(b
c)" is the same as "(a
* b)

False

The * operator also works on strings for which it performs repetition.

True

An error that is detected while the program is running is referred to as:

an exception

What output will the following Python statements produce?
>>> print (2*(3 - 1))
Select one:
a. 6
b. 5
c. 4 Correct
d. 3

4

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 Correct
b. return value
c. method
d. the special value None
e. global variable

argument

In a script, an expression all by itself is a legal statement, but it does not do anything.
Select one:
True
False Incorrect

True

What output will the following Python statements produce?
>>> print ((1+1)**(5-2))
Select one:
a. 16
b. 8 Correct
c. 4
d. 2

8

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 effect on the execution of the program. ? comment, The abilit

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 effect on the execution of the program. ? comment, The abilit

An expression is a combination of values, variables, and operators. If you type an expression on the command line, the interpreter evaluates it and displays the result.
Select one:
True Correct
False

True

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?

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 Correct
False

True

What is the output of the Python code below when run in script mode?
y = 3
x = 5
x + y
"x + y

no output

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())

ababababab

Python functions may or may not take arguments and may or may not return a result.
Select one:
True Correct
False

True

What output will the following Python statements produce?
>>> n = 17
>>> print (n)
Select one:
a. (n)
b. 17.0 Incorrect
c. n
d. 17

17

What output will the following Python statement produce?
>>> print ((1,000,000))
Select one:
a. 1,000
b. 1,000,000
c. (1, 0, 0) Correct
d. Error invalid type

(1, 0, 0)

When defining a Python function that has no parameters, the parentheses that follow the function's name are optional.
Select one:
True Incorrect
False

False

Which of the following is an invalid Python assignment statement?
Select one:
a. a = b = 123
b. '3' = 3
c. x = int("123")
d. y = None
e. z = "hi" * 10

'3' = 3

What output will the following Python statements produce?
>>>percentage = ( 60.0 * 100.0 ) / 55.0
>>>print (percentage)
Select one:
a. percentage
b. 109
c. 109.0909090909091
d. 109.0

109.0909090909091

When a Python function is called, inside the function, the arguments are assigned to variables called parameters.
Select one:
True
False

True

A program is a sequence of instructions that specifies how to perform a computation.
Select one:
True
False

True

The acronym PEMDAS is a way to remember the order of operations in Python.
Select one:
True
False

True

Programmers generally choose names for their variables that are meaningful and document what the variable is used for.
Select one:
True
False

True

What output will the following Python statements produce?
>>> print (2*3-1)
Select one:
a. 6
b. 5
c. 4
d. 3

5

A property of a program that can run on more than one kind of computer is called portability.
Select one:
True
False

True

Using Python keywords for variable names will result in a ________________
Select one:
a. runtime error
b. compile error
c. syntax error
d. semantic error

syntax error

What is Python's response to the command: type(123)
Select one:
a. <class 'float'>
b. <class 'bool'>
c. SyntaxError: invalid syntax
d. <class 'int'> Correct
e. <class 'str'>

<class 'int'>

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 Incorrect
b. 5 / 1.61
c. 1.61 / 5
d. 1.61 + 5
e. miles = "5 km

5 / 1.61

What is Python's response to the command: type(0.123)
Select one:
a. <class 'float'> Correct
b. <class 'bool'>
c. SyntaxError: invalid syntax
d. <class 'int'>
e. <class 'str'>

<class 'float'>

Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "4" called?
Select one:
a. a function
b. an operator
c. a prompt
d. a statement
e. a value Correct

a value

What is python's response to the command: type("0.123")
Select one:
a. <class 'float'>
b. <class 'bool'>
c. SyntaxError: invalid syntax
d. <class 'int'>
e. <class 'str'> Correct

<class 'str'>

Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "print(2 + 2)" called?
Select one:
a. a function
b. an operator
c. a prompt
d. a statement Correct
e. a value

a statement

Programming languages are ______ languages that have been designed to express computations.
Select one:
a. informal
b. mathematical
c. formal Correct
d. natural
e. logical

formal

What does the Python interpreter output for the following input?
>>> 1,234.567,890
Select one:
a. 1234
b. 1234.6
c. 1234.56789
d. (1, 234.567, 890) Correct
e. SyntaxError: invalid token

(1, 234.567, 890)

Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "print" called?
Select one:
a. a function Correct
b. an operator
c. a prompt
d. a statement
e. a value

a function

Which of the following is not a valid Python numeric literal:
Select one:
a. 123
b. 0123 Correct
c. 0.00
d. 12.3
e. 0.75

0123

Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text ">>>" called?
Select one:
a. a function
b. an operator
c. a prompt Correct
d. a statement
e. a value

a prompt

What does the following text indicate in a Python interpreter?
>>>
Select one:
a. A syntax error has occurred.
b. One value is much greater than another.
c. Shift a value to the right.
d. The interpreter is ready for you to enter code. Correct
e. The emoj

The interpreter is ready for you to enter code.

Which one of the following Python expressions generates a syntax error?
Select one:
a. 8 ^ 2 Incorrect
b. 8 ** 2
c. 8 +- 2
d. 8 += 2
e. 8 -+ 2

8 += 2

Consider the following text from a Python interpreter.
>>> print(2 + 2)
4
What is the text "+" called?
Select one:
a. a function
b. an operator Correct
c. a prompt
d. a statement
e. a value

an operator

An error in a program. ? bug, The process of finding and removing any of the three kinds of programming errors. ? debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer prog

An error in a program. ? bug, The process of finding and removing any of the three kinds of programming errors. ? debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer prog

string is a Python type that represents sequences of numeric values.
Select one:
True
False

False

Portability means the program is written in small chunks of code.
Select one:
True
False

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

8 ^ 2

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

8 ** 2

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
c. "21 minutes" + "21 seconds"
d. 21 * 60 + 21
e. seconds = 21 + "21 minutes

21 * 60 + 21

Which one of the following words best describes formal languages?
Select one:
a. ambiguity
b. literalness
c. poetry
d. prose
e. redundancy

literalness

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

True

What will the output of this python program be?
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)
Select one:
a. The area of the box is 1

The area of the box is 125.0

What output will the following statements produce using Python IDLE in interactive mode?
>>> n = 2
>>> n += 5
>>> n
Select one:
a. 7
b. 5
c. 2
d. an error message will occur

7

The following Python script will generate an error when executed. What is the cause of the error?
def function2(param):
print (param, param)
print (cat)
def function1(part1, part2):
cat = part1 + part2
function2(cat)
chant1 = "See You "
chant2 = "See Me

The variable cat is local to function1 and cannot be used in function2

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 b

A NameError because a variable not defined

What is the output of the Python code below?
n = int(10.)
print(isinstance(n, float), isinstance(n * 1.0, float))
Select one:
a. False
b. True False Incorrect
c. True True
d. False True
e. False False

False True

Chained conditionals are used when there are three or more possibilities.

'True'.

Boolean expressions control _________________
Select one:
a. recursion
b. conditional execution
c. alternative execution
d. all of the above

all of the above

Encapsulation is the process of wrapping a piece of code in a function

'True'

A development approach that that is intended to avoid a lot of debugging by only adding and testing small amounts of code at a time is called.
Select one:
a. structured development
b. incremental development
c. unit testing
d. Systems development life cyc

incremental development

Functions can only return Boolean expressions.

False

What output will the following Python script produce?
def function2(param):
print (param, param)
def function1(part1, part2):
cat = part1 + part2
function2(cat)
chant1 = "See You "
chant2 = "See Me "
function1(chant1, chant2)
Select one:
a. See You See Me

See You See Me See You See Me

A function that returns an integer value grater than 0 is called a boolean function.
Select one:
True
False

False

The modulus operator is the same as the divide operator.

False

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)
Select one:
a. 13.0
b. 0
c. Expression does not evaluate to boolean true
d. 13

13.0

The int function can convert floating-point values to integers, and it performs rounding up/down as needed.

False

Dead code" is code that performs calculations but never displays the results.

False

With built in functions, it is generally acceptable to take a "Leap of Faith".
Select one:
True
False

True

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
d. an error message will occur

7

What output will the following Python program produce?
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
b. None an error will be displayed
c. 8 4 2
d. 9 28 14 7 22 11 34 17 5

10 5 16 8 4 2

A Python loop where the terminating condition is never achieved is called _______.
Select one:
a. an infinite loop
b. a universal loop
c. a while loop
d. a for .. ever loop

an infinite loop

What does Python function subroutine do?
def subroutine( n ):
while n > 0:
print (n,)
n = n - 1
Select one:
a. Counts from 10 down to 0 and displays each number
b. Counts from n down to 1 and displays each number
c. Calculates the sum of n numbers greater

Counts from n down to 1 and displays each number

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
Select one:
a. Yes and no
b. No and no
c. Yes and yes
d. No and yes
e. Run-time error

Yes and yes

What is the value of the following Python expression?
"Xanadu" > "Yellowstone"
Select one:
True
False

False

An algorithm is a general process for solving a category of problems.
Select one:
True
False

True

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

[] operator

What output will the following Python commands produce?
n = 10000
count = 0
while n:
count = count + 1
n = n // 10
print (count)
Select one:
a. 5
b. 0
c. 10000
d. 1000

5

Python allows while loops inside while loops and if statements within the body of if statements.
Select one:
True
False

True

What is the output of the Python method call below?
"bib".find('b', 1, 2)
Select one:
a. 0
b. 2
c. -1
d. syntax error
e. 3

-1

The following Python code succeeds in modifying the first character of the string to "Y".
fred = "Hello"
fred[0] = "Y"
Select one:
True
False

False

The following Python code illustrates what programming concept?
bruce = 5
print (bruce,)
bruce = 7
print (bruce)
Select one:
a. Reassignment
b. Iteration
c. Logical operators
d. Conditionals

Reassignment

The statements inside of a Python loop are known as the ____ of the loop.
Select one:
a. body
b. expression
c. counter
d. block

body

Repeated execution of a set of programming statements is called repetitive execution.
Select one:
True
False

False

What is the output of the following Python program?
index = "Ability is a poor man's wealth".find("W")
print(index)
Select one:
a. 24
b. 0
c. 23
d. -1

-1

In Python, a list of characters is the same as a string.
Select one:
True
False Correct

False

To create a new object that has the same value as an existing object is knows as creating an alias.
Select one:
True Incorrect
False

False

The elements of a list are immutable.
Select one:
True
False Correct

False

The Python expression 'Unit 6'[-1] has value '6'.
Select one:
True Correct
False

True

What is the output of the following Python program?
mylist = [ [2,4,1], [1,2,3], [2,3,5] ]
a=0
total = 0
while a < 3:
b = 0
while b < 2:
total += mylist[a][b]
b += 1
a += 1
print(total)
Select one:
a. 14 Correct
b. 23
c. 0
d. 13

14

What is the output of the following Python 3 program?
mylist = ["now", "four", "is", "score", "the", "and seven", "time", "years", "for"]
a=0
while a < 8:
print(mylist[a],)
a = a + 2
Select one:
a. now is the time Correct
b. now is the time for
c. four sc

now is the time

A variable that has a data type of "str" cannot be part of a compound data type
Select one:
True
False Correct

False

What is the output of the following Python program?
index = "Ability is a poor man's wealth".find("w")
print(index)
Select one:
a. 24 Correct
b. 0
c. 23
d. -1

24

Traversal can only be accomplished with the "while" loop.
Select one:
True
False Correct

False

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)
Select one:
a. 14
b. 23 Correct
c. 0
d. 13

23

This Python code:
for fruit in ["banana", "apple", "quince"]:
print (fruit)
will produce this output:
banana apple quince
Select one:
True Incorrect
False

False

String objects are modified with string slices.
Select one:
True
False Correct

False

What is the output of the Python code below?
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] Correct

[3, 2, 1]

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]))
Select one:
a. now is the time
b. now is the time for
c. four score and seven years Corre

four score and seven years

What is the output of the Python code below?
my_list = [3, 2, 1]
print(my_list.sort())
Select one:
a. 0
b. {1, 2, 3}
c. None Correct
d. syntax error
e. [1, 2, 3]

None

What is the output of the following Python program?
fruit = "banana"
letter = fruit[1]
print (letter)
Select one:
a. b
b. a Correct
c. n
d. banana

a

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
Select one:
a. Yes and no
b. No and no
c. Yes and yes Correct
d. No and yes
e. Run-time error

Yes and yes

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 inverse:
result[val] = [key]
else:
result[val].append(key)
Select one:
a. a histogram
b. an inverted dictionary Cor

an inverted dictionary

Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What is word?
Select 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 n

A string with no newline

Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What is line?
Select one:
a. A file object
b. A list of characters
c. A list of words
d. A string that may have a newline Correct
e. A string w

A string that may have a newline

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
Select one:
a. now is the time Correct
b. now is the time for
c. for score an

now is the time

A development approach that that is intended to avoid a lot of debugging by only adding and testing small amounts of code at a time is called.
Select one:
a. structured development
b. incremental development Correct
c. unit testing
d. Systems development

incremental development

The Python line below causes "5 dollars" to be printed.
print('%d %s' % (5, 'dollars'))
Select one:
True Correct
False

True

Which of the following types are allowed for Python dictionary keys?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple Correct
e. All of the above

tuple

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)
Select one:
a. 1 and 2 are equal
b. 1 is less than 2 Correct
c.

1 is less than 2

Which one of the following Python expressions has the value 64?
Select one:
a. 8 ^ 2
b. 8 ** 2 Correct
c. 8 +- 2
d. 8 += 2
e. 8 -+ 2

8 ** 2

What is the output of the Python code below?
my_list = [3, 2, 1]
print(my_list.sort())
Select one:
a. 0
b. {1, 2, 3}
c. None Correct
d. syntax error
e. [1, 2, 3]

None

Which of the following types are allowed for Python dictionary values?
Select one:
a. dictionary
b. list
c. list of dictionaries
d. tuple
e. all of the above Correct

all of the above

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 Corr

an inverted dictionary

The correct answer is: Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. ? formal language, Any one of the language

The correct answer is: Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. ? formal language, Any one of the language

What is the output of the following statements?
pi = int(3.14159)
print (pi)
Select one:
a. 3 Correct
b. 3.0
c. 3.14159
d. 0

3

What is the output of the Python code below?
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] Correct

[3, 2, 1]

What is the output of the following Python statements?
def recurse(a):
if (a == 0):
print(a)
else:
recurse(a)
recurse(1)
Select one:
a. 0
b. 1
c. no output
d. RuntimeError: maximum recursion depth exceeded

maximum recursion depth exceeded

What output will the following python commands produce:
x = 5
if x % 2 == 0:
print (x)
else:
print (x, x%2)
Select one:
a. 5
b. 5 1 Correct
c. 2
d. 5 0

5 1

Given the following code, what will the output be?
import string
index = "Ability is a poor man's wealth".find("w")
print(index)
Select one:
a. 24 Correct
b. 0
c. 23
d. -1

24

Which one of the following Python expressions generates a syntax error?
Select one:
a. 8 ^ 2
b. 8 ** 2
c. 8 +- 2
d. 8 += 2 Correct
e. 8 -+ 2

8 += 2

What will the output of this python program be?
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)
Select one:
a. The area of the box is 1

The area of the box is 125.0

What output will the following code produce?
print ("%s %d %f" % (5, 5, 5))
Select one:
a. 5 5 5.000000 Correct
b. 5 5 5
c. 5 5.000000
d. 0 5 5.0

5 5 5.000000

A variable that has a data type of "str" cannot be part of a compound data type
Select one:
True
False Correct

'False'.

Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities beyond programming.
Select one:
True Correct
False

'True'.

Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v.
Select one:
True
False Correct

'False'.

What does function subroutine do?
def subroutine( n ):
while n > 0:
print (n,)
n -= 1
Select one:
a. Counts from 10 down to 0 and displays each number
b. Counts from n down to 1 and displays each number Correct
c. Calculates the sum of n numbers greater t

Counts from n down to 1 and displays each number

What output will the following code produce?
n = 10
while n != 1:
print (n,end=' ')
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 Correct
b. None an error will be displayed
c. 8 4 2
d. 9 28 14 7 22 11 34

10 5 16 8 4 2

What output will the following Python script produce?
def function2(param):
print (param, param)
def function1(part1, part2):
cat = part1 + part2
function2(cat)
chant1 = "See Me "
chant2 = "See You "
function1(chant1, chant2)
Select one:
a. See You See Me

See Me See You See Me See You

In Python, a list of characters is the same as a string.
Select one:
True
False Correct

'False'.

The elements of a list are immutable.
Select one:
True
False Correct

'False'.

What output will the following Python 3 program produce?
x = 5
if x % 2 == 0:
print (x)
else:
print (x, x%2)
Select one:
a. 5
b. 5 1 Correct
c. 2
d. 5 0

...

If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary.
Select one:
a. values and keys
b. indices
c. keys and values
d. values
e. keys Correct

keys

Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What does the program loop over?
Select one:
a. Lines in a file Correct
b. Lines in a list
c. Words in a dictionary
d. Words in a list
e. Words

Lines in a file

What output will the following python commands produce:
n = 10000
count = 0
while n:
count = count + 1
n = n // 10
print (count)
Select one:
a. 5 Correct
b. 0
c. 10000
d. 1000

5

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 Correct
d. a lookup
e. a reverse lookup

a list of tuples

: To create a new object that has the same value as an existing object is know as creating an alias.
Select one:
True
False Correct

'False'.

A loop where the terminating condition is never achieved is called an _______
Select one:
a. infinite loop Correct
b. universal loop
c. while loop
d. for .. ever loop

infinite loop

What is the value of the following Python expression?
not(True and False)
Select one:
True Correct
False

'True'.

What will the contents of mylist be after the following code has been executed?
>>> mylist = [1, 4, 2 3]
>>> mylist.append(5)
Select one:
a. [1, 4, 2, 3, 5] Correct
b. [5, 1, 4, 2, 3]
c. [null]
d. [1, 4, 2, 3]

[1, 4, 2, 3, 5]

What is the output of the following Python program?
try:
fin = open('answer.txt')
fin.write('Yes')
except:
print('No')
print('Maybe')
Select one:
a. Yes
b. No
c. Maybe
d. Yes
Maybe
e. No
Maybe Correct

No
Maybe

Consider the following Python program.
fin = open('words.txt')
for line in fin:
word = line.strip()
print(word)
What is fin?
Select one:
a. A file object Correct
b. A list of characters
c. A list of words
d. A string that may have a newline
e. A string wi

A file object

: The following code:
for fruit in ["banana", "apple", "quince"]:
print (fruit)
will produce the following output:
banana
apple
quince
Select one:
True Correct
False

'True'.

The correct answer is: An error in a program. ? bug, The process of finding and removing any of the three kinds of programming errors. ? debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical

The correct answer is: An error in a program. ? bug, The process of finding and removing any of the three kinds of programming errors. ? debugging, Any one of the languages that people have designed for specific purposes, such as representing mathematical

Handling an exception with a try statement is called throwing an exception.
Select one:
True
False Correct

'False'.

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 Correct

a reverse lookup

What is Python's response to the command: type(0.123)
Select one:
a. <class 'float'> Correct
b. <class 'bool'>
c. SyntaxError: invalid syntax
d. <class 'int'>
e. <class 'str'>

<class 'float'>