self quiz 6 p1
What output will the following interactive Python statements produce? >>> n = 2 >>> n += 5 >>> n
7
What output will the following statements produce using Python IDLE in interactive mode? >>> n = 2 >>> n += 5 >>> n
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 " function1(chant1, chant2)
The variable cat is local to function1 and cannot be used in function2
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]))
four score and seven years
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]))
four score and seven years
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
The first part of a compound statement begins with a keyword and ends with a colon ( : )
header
The operands of the logical operators should be boolean expressions, but Python is not very strict. Any nonzero number is interpreted as True.
true
True or False: A local variable is a variable defined inside a function that can only be used inside its function.
true
What is the value of the following Python expression? (0, 1, 5, 2) > (0, 1.0, 4, 3.1)
true
With built in functions, it is generally acceptable to take a "Leap of Faith".
true
Which of the following types are allowed for Python dictionary keys?
tuple
Expressions evaluate to either True or False. What will be the output of the following Python 3 program? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!")
we are the knights who say, "Ni!"
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
yes and yes
Will the Python code below print something? And will it terminate? def print_n(s, n): if n > 0: print(s) print_n(s, n-1) return n n = 3 while print_n("hi", n): print_n("there!", n) n = 0
yes and yes
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)
23
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)
23
What is the output of the following Python program? index = "Ability is a poor man's wealth".find("w") print(index)
24
What is the output of the following Python program? index = "Ability is a poor man's wealth".find("w") print(index)
24
What is the output of the following Python program? pi = int(3.14159) print (pi)
3
What is the value of the variable index after the Python code below is executed? word = 'bAnana' index = word.find('a')
3
What is the output of the following Python program? pi = foat(3.14159) print (pi)
3.14159
What output will the following Python commands produce? n = 10000 count = 0 while n: count = count + 1 n = n // 10 print (count)
5
What output will the following Python program produce? n = 10000 count = 0 while n: count = count + 1 n = n / 10 n=int(n) print(count)
5
What output will the following Python 3 program produce? x = 5 if x % 2 == 0: print (x) else: print (x, x%2)
5.1
The statements inside of a Python loop are known as the ____ of the loop.
body
What is the return type of the Python function shown below? def is_divisible(x, y): return (x % y) == 0
bool
What is the return type of the Python function shown below? isinstance(10.001, float)
bool
What is the return type of the Python function shown below? isinstance(10.001, float)
bool
"Dead code" is code that performs calculations but never displays the results.
false
A function that returns an integer value grater than 0 is called a boolean function.
false
A variable that has a data type of "str" cannot be part of a compound data type
false
Functions can only return boolean expressions.
false
Given a Python dictionary d and a value v, it is efficient to find the corresponding key: d[k] = v.
false
In Python, a list of characters is the same as a string.
false
Repeated execution of a set of programming statements is called repetitive execution.
false
String objects are modied with string slices.
false
String objects are modified with string slices.
false
The Python 3 program below prints the number 3. s = "Python3" print(s[len(s)])
false
The elements of a list are immutable.
false
The following Python code succeeds in modifying the first character of the string to "Y". fred = "Hello "fred[0] = "Y"
false
The following Python code succeeds in modifying the first character of the string to "Y". fred = "Hello" fred[0] = "Y"
false
The int function can convert floating-point values to integers, and it performs rounding up/down as needed.
false
The modulus operator is the same as the divide operator.
false
This Python code: for fruit in ["banana", "apple", "quince"]: print (fruit) will produce this output: banana apple quince
false
This Python code: for fruit in ["banana", "apple", "quince"]: print (fruit) will produce this output: banana apple quince
false
To create a new object that has the same value as an existing object is knows as creating an alias.
false
Traversal can only be accomplished with the "while" loop.
false
What is the value of the following Python expression? "Xanadu" > "Yellowstone"
false
for fruit in ["banana", "apple", "quince"]: print (fruit) will produce this output: banana apple quince
false
The order in which statements are executed during a program run.
flow of execution
A stack diagram shows the value of each variable and the function to which each variable belongs.
true
An algorithm is a general process for solving a category of problems.
true
Chained conditionals are used when there are three or more possibilities.
true
Encapsulation is the process of wrapping a piece of code in a function
true
Python allows while loops inside while loops and if statements within the body of if statements
true
Python allows while loops inside while loops and if statements within the body of if statements.
true
Python dictionaries are mutable.
true
Python tuples are immutable.
true
The Python expression 'Unit 6'[-1] has value '6'.
true
What is the output of the Python code below? my_tup = (3, 2, 1, 2) print(tuple(sorted(my_tup)))
(1, 2, 2, 3)
What is the output of the Python method call below? "bib".find('b', 1, 2)
-1
What is the output of the following Python program? index = "Ability is a poor man's wealth".find("W") print(index)
-1
What is the output of the following python programm? Index="Ability is a poor man's wealth". Find("W") Print(index)
-1
What is the output of the following Python 3 statements? 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)
1 is less than 2
What output will the following Python 3 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
10 5 16 8 4 2
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
10 5 16 8 4 2
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
10 5 16 8 4 2
What output will the following Python commands produce? >>> percentage = oat ( 60 * 100) / 55 >>> print (percentage)
109.0909090909091
What output will the following Python program produce? def area(l, w): temp = l * w return temp l = 4.0 w = 3.25 x = area(l, w) if ( x ): print (x)
13.0
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)
13.0
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)
13.0
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)
14
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)
14
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 = 2test_function(l, w, h) print ("The area of the box is ", length*width*height)
A NameError because a variable not defined
What does Python function subroutine do? def subroutine( n ): while n > 0: print (n,) n = n - 1
Counts from n down to 1 and displays each number
What does the following Python 3 function do? def subroutine(n): while n > 0: print (n,) n -= 1
Counts from n down to 1 and displays each number
In the following segment of Python code, what do we call the portion of the statement that follows the dot('.capitalize')? str.capitalize('maryland')
Method
What output will the following Python 3 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)
See You See Me See You See Me
What will the contents of mylist be after the following Python code has been executed? >>> mylist = [1, 4, 2, 3] >>> mylist.append(5)
[1, 4, 2, 3, 5]
What is the output of the Python code below? my_list = [3, 2, 1] print(my_list)
[3, 2, 1]
A Python string is a sequence of characters. You can access the string characters with the _______.
[] operator
What is the output of the following Python program? fruit = "banana" letter = fruit[1] print (letter)
a
Assume that d is a Python dictionary. What does the following Python code produce? for k in d: if d[k] == v: return k
a reverse lookup
Which of the following types are allowed for Python dictionary values?
a. dictionary list/ list of dictionaries tuple
A Python loop where the terminating condition is never achieved is called _______.
an infinite loop
A loop where the terminating condition is never achieved is called _______.
an infinitive loop
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)
an inverted dictionary
What is the output of the Python code below? s = "help" for letter in s[1:]: last = letter break print(last)
e
What is the output of the Python code below? print(dict().get("no", "help!"))
help!
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:
incremental development
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.
incremental development
If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary.
keys
A variable defined inside a function that can only be used inside its function.
local variable
What is the output of the Python code below? my_list = [3, 2, 1] print(my_list.sort())
none
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
now is the time
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
now is the time
The following Python 3 code is an example of what principle? bruce = 5 print (bruce,) bruce = 7 print (bruce)
reassignment
The following Python code illustrates what programming concept?bruce = 5 print (bruce,) bruce = 7 print (bruce)
reassignment
A graphical representation of functions values to which they refer.
stack diagram