Python
Python embodies elements of which programming paradigm? Procedural programming Object-oriented programming Functional programming All of the above
All of the above
There is no way to stop an infinite loop. True False
False
The pass statement has no effect on the program state. True False
True
Which of the following string literals is NOT valid? "\"\n" ""\n"" '"' '\n'
""\n""
What is ASCII? A technique for ordering Unicode characters. A subset of Unicode containing primarily English characters and basic symbols. A technique for representing Unicode characters in memory. A set of non-printable Unicode characters. None of the above.
A subset of Unicode containing primarily English characters and basic symbols.
The stop value passed as an argument to the range function is NOT included in the range produced. True False
True
The value assigned to a variable could be a floating point number. True False
True
The value of a variable can change throughout a program. True False
True
The values stored in a list can be changed. True False
True
Using a while loop to check each input value for correctness is a form of input validation. True False
True
Variables declared inside a function cannot be accessed from outside that function. True False
True
Which of the following is NOT a reason to use a constant? Constants prevent inadvertent programming errors. Constants convey more meaning than literals. Constants minimize the need for input validation. Constants make maintenance tasks easier and safer.
Constants minimize the need for input validation.
Strings containing non-alphabetic characters cannot be compared using the relational operators. True False
False
The Olympic rings program uses a loop to draw the five rings. True False
False
The body of a for loop cannot contain another for loop. True False
False
The break statement is essentially the same as a GOTO statement in older programming languages. True False
False
The effect of the setheading depends on the current heading of the turtle. True False
False
The from clause of an import statement lets you define an alias for a module or function. True False
False
The pass statement is useless. True False
False
The random values used in the starbursts program were all determined by calls to the randint function from the Python Standard Library. True False
False
The read method of a file object reads the contents of a file one line at a time. True False
False
The sample function in the random module takes a sample with replacement. True False
False
The start value passed as an argument to the range function cannot be negative. True False
False
The step value passed as an argument to the range function cannot be negative. True False
False
The value of the expression len(list) is one less than the number of elements in the list. True False
False
The write method adds a newline character to the end of the output. True False
False
The write method automatically adds line numbers to the output. True False
False
To change the algorithm for finding a minimum value into one that finds a maximum value, the range used in the for loop would change. True False
False
When using relational operators to compare character strings, 'ZEBRA' comes before 'ALLIGATOR'. True False
False
Debugging is the process of: Finding the root cause of an error and fixing it. Running a program with all possible inputs. Proving that a program produces the correct answers. Demonstrating the a program follows its specification.
Finding the root cause of an error and fixing it.
What is lexicographic ordering? Ordering strings based on their length. Ordering letters based on their case (lowercase or uppercase). Ordering characters based on a character set. Ordering words based on their language. Ordering sushi at a Japanese restaurant.
Ordering characters based on a character set.
If you use a from clause on an import statement, you don't have to use the module name to refer to a function from that module. True False
True
In Python, the relational operators can be used to put character strings in alphabetical order. True False
True
In a programming language, a syntactically valid statement has only one meaning. True False
True
In some cases, a sentinel value can be used to signal the end of input. True False
True
In the honeycomb program, the draw_honeycomb function calls the draw_hexagon function. True False
True
Swapping two elements in a list requires three assignment statements. True False
True
The open function can be used to open an input file or create an output file. True False
True
Two functions can have the same name if they are in different modules. True False
True
When using relational operators to compare character strings, 'Music' comes before 'music'. True False
True
Which of the following is a good rule of thumb regarding break and continue statements? Avoid using them if at all possible. Always use them if the logic of the loop permits it. Use them sparingly, and only if they make the logic more readable. Use them in for loops but not in while loops.
Use them sparingly, and only if they make the logic more readable.
Which line of code is equivalent to the following?depth += 50 * offset depth = depth + (50 * offset) offset = depth + (50 * offset) offset = depth + 50 * offset depth = (depth + 50) * offset
depth = depth + (50 * offset)
Which way would the turtle be facing after executing the following code? turtle.setheading(270) turtle.right(20) turtle.left(65) down and right (southeast) up and left (northwest) down and left (southwest) down (south) up (north) up and right (northeast)
down and right (southeast)
In the honeycomb program, the draw_hexagon function is called seven times. True False
False
In the random turtle walk program, the loop control variable is used to determine whether the turtle turns right or left. True False
False
In the starbursts program, the number of starbursts drawn is determined randomly. True False
False
The choice function in the random module lets you choose multiple elements from a list. True False
False
The continue statement must be executed after a break statement is executed. True False
False
The less than operator (<) should not be used to compare floating point values. True False
False
The loop in the star program controls how long each line in the star is. True False
False
An if statement affects a program's flow of control. True False
True
An import statement finds a module and binds it to a name you can use in a program. True False
True
Python comments begin with a hash mark (#) and extend to the end of the line. True False
True
Python is a general-purpose programming language, appropriate for solving problems in many areas of computing. True False
True
Python uses the Unicode character set to represent characters. True False
True
Given the following line of code, which expression would produce the substring 'ledge'? words = 'Knowledge is power.' words[4:8] words[4:9] words[5:9] words[5:10]
words[4:9]
The Python for loop is what other languages refer to as a for-each loop. True False
True
The Unicode character set currently represents over 100,000 characters. True False
True
The best way to read a file line by line is to use a for loop to iterate over the file object itself. True False
True
The body of a while loop may never execute. True False
True
The break and continue statements both alter the flow of control in a loop. True False
True
The input, int, and float functions are all built-in functions. True False
True
The loop in the curved spiral program controls both how many lines are drawn and how long each one is. True False
True
Given the following line of code, what is the value of the expression nums.index(20)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] 2 3 4 5
4
Which range is produced by the function call range(4, 10)? 4 5 6 7 8 9 5 6 7 8 9 4 5 6 7 8 9 10 5 6 7 8 9 10
4 5 6 7 8 9
What output is produced by the following code?print(15 + 30) 1530 "1530" 45.0 45
45
How many times will the following code print the word 'wow'?for val in range(5, 10): print('wow') 4 5 6 9 10
5
If the variable word refers to the string 'programming', what does the expression word[2:] produce? 'rogram' 'rogramming' 'ogramming' 'ogram'
ogramming
The turtle circle command can be used to draw a regular polygon. True False
true
You must use a print statement to display the result of an expression in the Python shell. True False
false
What is the default flow of control through a function? binary linear repetitious conditional
linear
Computing the wrong answer is an example of what kind of error? syntax error logic error interface error runtime error
logic error
Which of the following is NOT a valid Python identifier? 1stPlace place1 FIRST_PLACE first_place
1stPlace
Which of the following hex strings represents the color white? '#FFFFFF' '#640000' '#646464' '#000000'
'#FFFFFF'
If a variable called business refers to the string 'Time Warner', what is the result of the expression business[6]? 'a' ' ' 'r' 'W'
'a'
What is the result of the expression math.floor(12.843)? 0 10 12 13
12
Which range is produced by the function call range(12, 5, -2)? 11 10 9 8 7 6 5 12 10 8 6 4 10 8 6 12 10 8 6
12 10 8 6
Given the following line of code, what is the value of the expression nums.count(80)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] 1 2 3 4
3
Given the following line of code, what is the value of the expression nums.index(80, 2)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] 1 2 3 4
3
If the value of num is 7 and the value of max is 10, what is the value of num after the following statement is executed?num = max if max < num else max - num 3 4 7 10
3
What is the result of the expression 43 % 5? 3 4 8 8.6
3
The expression random.randrange(5, 10) will produce a value in what range? 5 to 9 10 to 15 5 to 10 0 to 15
5 to 9
The expression random.randint(6, 12) will produce a value in what range? 5 to 11 6 to 13 6 to 11 6 to 12
6 to 12
Which of the following is a relational operator? / <= not and
<=
Given the following line of code, which expression would produce the substring 'snapper'?young = 'whippersnapper' young[7:14] young[7:] young[-7:] young[7:len(young)] All of the above. None of the above.
All of the above.
Which of the following would cause a runtime error? Dividing by zero. Leaving a quotation mark off of the end of a character string. Computing the wrong result. Misspelling a keyword. Exactly! Since dividing by zero is an undefined operation, the program halts execution.
Dividing by zero.
In Python, the assignment statement is also an expression. True False
False
A Python block comment begins with a double slash (//). True False
False
What is the output of the following statement? print('He said \\Expelliarmus\\'); He said \Expelliarmus\ He said \\Expelliarmus\\ He said 'Expelliarmus' He said \'Expelliarmus\' No output. This statement contains a syntax error.
He said \Expelliarmus\
Thonny is best described as which of the following? Integrated Development Environment (IDE) Text editor Package manager Debugger Command shell
Integrated Development Environment (IDE)
What output is produced by the following code?print('Jan', 'Feb', 'Mar', sep='-') Jan-Feb-Mar- Jan - Feb - Mar Jan- Feb- Mar- Jan-Feb-Mar
Jan-Feb-Mar
What output is printed by the following code?str = 'Rephactor Python' index = 0 num = 0 while index < len(str): if str[index] == 'o': num += 1 index += 1 print('Num:', num) Num: 0 Num: 2 Num: 10 Num: 16 No output because the code contains an infinite loop.
Num: 2
Which of the following statements is true? The break statement terminates the loop completely. The break statement causes an error to be generated. The break statement breaks out of the outermost loop. The break statement terminates the current iteration of the loop.
The break statement terminates the loop completely.
Which of the following is NOT true regarding the return statement? When a return statement executes, the function stops executing immediately. The keyword return is usually followed by an expression. A function can have more than one return statement. The last statement in a function must be a return statement.
The last statement in a function must be a return statement.
Finding a minimum value requires that every element in the list be examined. True False
True
What does list contain after the following code is executed? list = [77, 41, 92, 30, 38, 12, 63] list.sort() list.insert(2, 88) list.pop(5) [92, 77, 88, 63, 41, 30, 12] [12, 88, 30, 38, 63, 77, 92] [12, 30, 88, 38, 41, 77, 92] [12, 30, 88, 38, 63, 77, 92]
[12, 30, 88, 38, 41, 77, 92]
What output will the following code produce?list1 = [2, 9, 5, 7] list2 = [1, 4, 2, 3] print(list1 + list2) [2, 9, 5, 7, 1, 4, 2, 3] [1, 2, 2, 3, 4, 5, 7, 9] [3, 13, 7, 10] [21, 94, 52, 73]
[2, 9, 5, 7, 1, 4, 2, 3]
Which of the following expressions could be used to determine if a is not less than b? a < b a > b a !< b a >= b
a >= b
For Python, the term data type can be used interchangeably with what other term? class index object sequence
class
If a variable called word refers to the string 'committee', what is the result of the expression word.strip('m')? 'committee' 'coittee' 'comittee' 'co'
committee
Which of the following is NOT a constant from the Python Standard Library? math.e conversions.KILOMETERS_PER_MILE math.pi tkinter.NE
conversions.KILOMETERS_PER_MILE
Which statement would produce the following output? Eeny Meeny Miny Moe print('Eeny\t\nMeeny\tMiny\t\nMoe'); print('Eeny\t\tMeeny\tMiny\t\tMoe'); print('Eeny\n\tMeeny\n\tMiny\n\tMoe'); print('Eeny\n\tMeeny\nMiny\n\tMoe');
print('Eeny\n\tMeeny\nMiny\n\tMoe');
Which category of data types represents an ordered collection of values? dictionary boolean numeric sequence
sequence
Given the following line of code, which expression would produce the list ['DE', 'MD', 'VA']?states = ['CA', 'WY', 'DE', 'MD', 'VA', 'FL', 'TX'] states[3:6] states[3:5] states[2:5] states[2:4]
states[2:5]
What do the characters in a Unicode escape sequence represent? the hexadecimal code for a particular Unicode character a range of Unicode characters the ASCII code for the equivalent Unicode character the set of characters terminating in a particular Unicode character
the hexadecimal code for a particular Unicode character
If the variable machine refers to the string 'computer', what does the expression machine[0:len(machine):2] produce? 'optr' 'comp' 'cmue' 'uter'
'cmue'
Which of the following conclusions is NOT true when using relational operators to compare character strings? 'ultrasonic' comes before 'ultraviolet' 'able' comes before 'baker' 'moon' comes before 'moonwalk' 'fantastic' comes before 'Great'
'fantastic' comes before 'Great'
If the variable noise refers to the string 'hullaballoo', what does the expression noise[:8] produce? 'hullaball' 'hullabal' 'laballoo' 'loo'
'hullabal'
Which of the following conclusions is NOT true when using relational operators to compare character strings? 'desk' comes before 'desktop' 'reset' comes before 'reserve' 'bemuse' comes before 'bewitch' 'Dracula' comes before 'Frankenstein'
'reset' comes before 'reserve'
If the variable blah_blah refers to the string 'gobbledygook', what does the expression blah_blah[-5:] produce? 'gook' 'ygook' 'gobbl' 'dygook'
'ygook'
Python is dynamically typed, meaning each variable can only store one type of value. True False
False
Which range is produced by the function call range(5)? 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 1 2 3 4 5
0 1 2 3 4
If the variable num contains a positive integer, what are the only two possible results of the expression num % 2? -1 and 1 0 and 2 0 and 1 1 and 2
0 and 1
The expression random.randrange(30) will produce a value in what range? 1 to 29 1 to 30 0 to 30 0 to 29
0 to 29
If the variable str refers to the string 'ABC123XYZ', what does the expression str[3:7] produce? 'C123X' '123XY' 'C123' '123X'
123X
If a variable called address refers to the string '123 Main Street', what is the result of the expression address.find('3')? -1 2 3 That expression would cause an error.
2
What value is printed by the following code?my_list = [53, 17, 39, 22, 81, 69] print(my_list[-3]) 39 22 81 69 No output. An error will occur.
22
What value is printed by the following code?my_list = [53, 17, 39, 22, 81, 69] print(my_list[3]) 39 17 22 6
22
What value is stored in num after the following code is executed?list = [2, 4, 6, 8, 10] num = 0 for val in list: if val != 6: num = num + val 0 5 10 24 30
24
What is a docstring? A character string used as a comment in a program. A character string used to debug a program. A series of documents concatenated into a single document. A series of characters concatenated into a single line of text.
A character string used as a comment in a program.
What causes an infinite loop? A loop body that is never executed. A loop condition that is never false. A loop condition that is always false. A loop control variable that is repeatedly modified.
A loop condition that is never false.
How do you read an integer from a text file? By calling the read_int method of the file object. By calling the read_num method of the file object. By reading it as a string and converting it to an integer. By reading it as a floating-point value and truncating it.
By reading it as a string and converting it to an integer.
A Python comment cannot appear on a line that contains an executable statement. True False
False
A Python function must have at least one parameter. True False
False
A character encoding is the list of all characters used by a programming language. True False
False
A linear search examines every element in the list. True False
False
A nested loop is required to draw a squared-corner spiral. True False
False
A program that runs without generating a runtime error will produce correct results. True False
False
All Python data types are immutable. True False
False
All elements in a Python list must have the same data type. True False
False
An assignment statement affects a program's flow of control. True False
False
Constants automatically convert between units of measure. True False
False
Functions of the math module do not have to be imported. True False
False
If a variable called user_id refers to the string 'AEinstein12', what is the result of the expression user_id.isalpha()? True False
False
Python constants cannot be created for floating-point values. True False
False
What is the role of the seed value of a random number generator? It's the maximum value that can be generated. It's the minimum value of any range produced by the generator. It's a number that is the basis of the calculated pseudorandom numbers. It's the maximum number of values that can be produced by the generator.
It's a number that is the basis of the calculated pseudorandom numbers.
Which of the following identifiers follows the naming convention for a Python constant? maxPenalties MAXPENALTIES MAX_PENALTIES Max_Penalties
MAX_PENALTIES
Which of the following would cause a syntax error? Misspelling a word in the output. Failing to follow the program specification. Misspelling a keyword. Dividing by zero.
Misspelling a keyword.
What output would be produced when the following code is executed?state = 'Mississippi' print(state.replace('is', 'was)) Mwasswassippi Mwassissippi Mwaswasippi Mwasswasswaspi
Mwasswassippi
Why don't we use natural languages (like English) to program a computer? Natural languages are semantically ambiguous. Natural languages don't have syntax rules. It's often hard to understand people when they speak. There are too many words and phrases to understand in natural languages.
Natural languages are semantically ambiguous.
If a variable called greeting refers to the string 'hello', what does the expression greeting.upper() accomplish? Returns a new string containing the characters 'HELLO' Returns a new string containing the characters 'Hello' Converts the characters in the string object to 'Hello' Converts the characters in the string object to 'HELLO'
Returns a new string containing the characters 'HELLO'
In the flower design program, which diamond is drawn first? The one that points northeast. The one that points southeast. The one that points northwest. The one that points southwest.
The one that points southeast.
What is a program's flow of control? The order in which interface events are processed. The order in which loop bodies are executed. The order in which functions are called. The order in which statements are executed.
The order in which statements are executed.
What is the syntax of a language? The meaning of a language element. The rules that determine how words and symbols can be combined. A specification that lists a program's requirements. A list of errors that can occur in a program.
The rules that determine how words and symbols can be combined.
What does the following statement print?print('Invalid' if count <= 0 else count) The value of count, or 'Invalid' if count is negative. Zero, or 'Invalid' if count is positive. Zero, or 'Invalid' if count is negative. The value of count, or 'Invalid' if count is positive.
The value of count, or 'Invalid' if count is negative.
If the value of weight is 7, what does the following statement print?print('The weight is ' + ('even' if weight % 2 == 0 else 'odd')) The weight is even The weight is odd The weight is void The weight is NAN
The weight is odd
A character string can be used as the condition of an if statement. True False
True
A comment in a Python program is ignored by the interpreter. True False
True
A for loop can be used to compute the sum of all values in a list. True False
True
A for loop is a good way to access each character in a string. True False
True
A function can return a boolean result. True False
True
A function parameter ceases to exist when the function returns to the caller. True False
True
A pass statement can be used as the body of an if statement, for loop, function definition, or class definition. True False
True
A while loop affects a program's flow of control. True False
True
A with statement will automatically close an open file when processing is complete. True False
True
After a function finishes executing, control returns to the place the function was called. True False
True
An entire module can be imported using one import statement. True False
True
Given the following line of code, which list is produced by the expression states[-4:]? states = ['CA', 'WY', 'DE', 'MD', 'VA', 'FL', 'TX'] ['DE', 'MD', 'VA', 'FL', 'TX'] ['VA', 'FL', 'TX'] ['CA', 'WY', 'DE', 'MD'] ['MD', 'VA', 'FL', 'TX']
['MD', 'VA', 'FL', 'TX']
What does the list states contain after the following code is executed? states = ['NJ', 'TN', 'WI', 'UT'] states.extend(['PA', 'KY', 'NY']) states.remove('UT') states.sort(reverse=True) ['NJ', 'TN', 'WI', 'PA', 'KY', 'NY'] ['WI', 'UT', 'TN', 'PA', 'NY', 'NJ', 'KY'] ['WI', 'TN', 'PA', 'NY', 'NJ', 'KY'] ['WI', 'PA', 'TN', 'NJ', 'NY', 'KY']
['WI', 'TN', 'PA', 'NY', 'NJ', 'KY']
Given the following line of code, which list is produced by the expression values[3:8]? values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] [32, 95, 66, 58, 81] [18, 32, 95, 66, 58, 81, 20] [18 32, 95, 66, 58, 81] [32, 95, 66, 58, 81, 20]
[32, 95, 66, 58, 81]
Given the following line of code, which list is produced by the expression values[:8]? values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] [18, 32, 95, 66, 58, 81, 20, 62] [79, 40, 18, 32, 95, 66, 58] [32, 95, 66, 58, 81, 20, 62] [79, 40, 18, 32, 95, 66, 58, 81]
[79, 40, 18, 32, 95, 66, 58, 81]
What does list contain after the following code is executed?list = [82, 27, 66, 18, 40, 93, 85, 29] list.append(50) list.insert(3, 99) list.pop() [82, 27, 99, 66, 18, 40, 93, 85, 29] [27, 66, 99, 18, 40, 93, 85, 29, 50] [50, 82, 27, 99, 66, 18, 40, 93, 85] [82, 27, 66, 99, 18, 40, 93, 85, 29]
[82, 27, 66, 99, 18, 40, 93, 85, 29]
Given the following line of code, which list is produced by the expression values[4:]?values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] [95, 66] [95, 66, 58, 81, 20, 62] [32, 95, 66] [32, 95, 66, 58, 81, 20, 62]
[95, 66, 58, 81, 20, 62]
Which of the following is NOT a repetition statement in Python? if statement while statement for statement They are all repetition statements.
if statement
5 What technique is used to put Unicode characters and strings in order? character encoded ordering lexicographic ordering ASCII ordering alphabetical ordering
lexicographic ordering
Which assignment statement is functionally equivalent to the following if statement?if num1 > total: num1 = total else num1 = 0 num1 = 0 if num1 > total else total num1 = total if num1 > 0 else 0 num1 = total if num1 > total else 0 num1 = 0 if total > 0 else total
num1 = total if num1 > total else 0
The Python type conversion functions are actually what kind of functions? iterators object constructors user-defined types predicate functions
object constructors
Which statement would produce the following output?"Oom Pah Pah Oom Pah Pah," that's how it goes. print("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes."); print('\qOom Pah Pah Oom Pah Pah,\q that's how it goes.'); print('\nOom Pah Pah Oom Pah Pah,\n that's how it goes.'); print(""Oom Pah Pah Oom Pah Pah," that's how it goes.");
print("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes.");
Which of the following expressions would produce a value in the range 1 to 10? random.randint(1, 9) random.randrange(1, 11) random.randint(1, 11) random.randrange(1, 10)
random.randrange(1, 11) Yes!
Full documentation about the Python Standard Library can be found online. True False
true
What is the result of the expression 7 // 2? 0 1 3 3.5
3
If the current value of the variable num is 4, what value will be stored in num after the following line of code is executed?num += 2 2 4 6 8
6
What output does the following code produce?print('Ready', end=' ') print('Set', end='') print('Go') Ready SetGo Ready SetGo Ready Set Go Ready Set Go
Ready SetGo
If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3? YodaYodaYoda YYYooodddaaa 12 The expression will generate an interpreter error.
YodaYodaYoda
What output does the following code produce?print('apple', 'banana') apple banana apple banana apple, banana applebanana
apple banana
A Python program must be enclosed in curly braces { } to be executed. True False
false
Which of the following identifiers follows the convention for naming Python variables? totalValue TOTAL_VALUE total_value Total_Value
total_value
Built-in functions of the Python Standard Library can be used without being imported. True False
true
The Python shell has an integrated help system. True False
true
Which way would the turtle be facing after executing the command turtle.setheading(135)? right (east) left (west) down and left (southwest) down and right (southeast) up and left (northwest) up and right (northeast)
up and left (northwest)
What is the result of the expression max(6, 17)? 0 6 17 23
17
What is the Python Standard Library? A collection of programming components that can be used in any Python program. A set of officially sanctioned books about Python. A collection of software tools that support the development of Python programs. The set of documents that define the Python language.
A collection of programming components that can be used in any Python program.
What issue must be addressed when printing a long character string? A regular string literal cannot span across multiple lines. The print method cannot print character strings. The print method has a maximum number of characters it can accept. The string must be subdivided into sections of 50 characters or less.
A regular string literal cannot span across multiple lines.
What is the Python shell? An integrated development environment for developing Python programs. An alternative to IDLE or Thonny. A window in which Python statements and expressions are executed immediately. A help system for Python programming.
A window in which Python statements and expressions are executed immediately.
A Python program must compiled into an executable form before it can be run. True False
False
Python represents a color using the CMYK color model. True False
False
Python variables are created using an assignment statement. True False
true
The Python shell is great for exploring Python language features. True False
true
The Python turtle graphics module is based on the programming language Logo developed in the 1960s. True False
true
The relational operators all return boolean results. True False
true
You can store a value in a variable in the Python shell. True False
true
You cannot change the contents of Python character string once it has been created. True False Excellent! Python strings are immutable.
true
Equal contributions of the three components in an RGB color results in various shades of what? green gray blue red
Gray
Who developed the Python programming language? James Gosling Bjarne Stroustrup Guido van Rossum Yukihiro Matsumoto
Guido van Rossum
Python 3 is backward compatible to Python 2. True False
false
The Python programming language was so named after a snake was discovered in the creator's office. True False
false
The goto command moves the turtle without drawing a line. True False
false
The origin point (0, 0) of the turtle coordinate system is in the upper left corner of the graphic screen. True False
false
If the current value of the variable num1 is 2 and the current value of the variable num2 is 3, what value will be stored in num2 after the following line of code is executed?num2 /= num1 * num2 0.0 0.5 1.0 1.5
0.5
Which value of num will cause the print statement in the following code to be executed?if num < 15: if num + 7 >= 20: print('There you go!') 5 10 13 18
13
If a variable called pioneer refers to the string 'Grace Murray Hopper', what is the result of the expression len(pioneer)? 17 18 19 20
19
A turtle draws a filled circle using the fill_circle command. True False
False
All mathematical functions in Python are part of the math module. True False
False
An if statement cannot have both an elif and an else clause. True False
False
In dynamically typed languages, variables are declared to store a specific type of data. True False
False
What output does the following code produce?print('Total: ' + 100 + 20) Total: 120 Total: 10020 Total: 1000200 No output. This line would produce an error.
No output. This line would produce an error.
Which of the following statements is true? An if statement must contain an else clause. An if statement is an example of a repetition statement. The body of an if statement must be enclosed in braces. The statements in the body of an if must be indented.
The statements in the body of an if must be indented.
What will happen if the variable total has the value 5 when the following code is executed? if total > 8: print('collywobbles') The word collywobbles is not printed and processing continues. The word collywobbles is printed and then processing continues. The word collywobbles is not printed, but an error message is. The word collywobbles is not printed and an exception is thrown.
The word collywobbles is not printed and processing continues.
The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue. True False
True
Which of the following is NOT a principle embraced by the Python programming language? Verbose is better than succinct. Complex is better than complicated. Beautiful is better than ugly. Simple is better than complex. Readability counts. Explicit is better than implicit.
Verbose is better than succinct.
The position of a circle depends on the current heading of the turtle. True False
false
What operator is used to perform string concatenation in Python? @ & * +
+
If the turtle is currently facing up (north), which way would it be facing after executing the command turtle.right(45)? left (west) up and left (northwest) down and left (southwest) up and right (northeast) right (east) down and right (southeast)
up and right (northeast)
If a variable called son refers to the string 'Justin', what is the result of the expression son[-3]? 'tin' 's' 't' The expression will generate an interpreter error.
't'
What is the result of the expression math.pow(3, 3)? 0 6 9 27
27
If the current value of the variable size is 2, what value will be stored in size after the following line of code is executed?size *= 3 2 3 5 6
6
If the current value of the variable count is 2, what value will be stored in count after the following line of code is executed?count += count * 3 2 3 6 8
8
What value is assigned to the variable num by the following statement if the current value of num is 4?num = num * 2 2 4 6 8
8
Which of the following does the input function NOT do when it is called? Wait for the user to type information and press Enter. Print a message if provided. Convert the user input to an integer. Return the value typed by the user.
Convert the user input to an integer.
Python variables that represent integers are NOT object reference variables. True False
False
Running a program that contains errors will cause the Thonny development environment to terminate. True False
False
The arithmetic operators have a lower precedence than the relational operators. True False
False
The assignment operator has higher precedence than the arithmetic operators. True False
False
The expression x ^ y raises the value x to the power y. True False
False
The input function will produce an error if the value read is not numeric. True False
False
The stroke color of a filled turtle shape must be the same as the fill color. True False
False
The value assigned to a variable must be numeric. True False
False
The webcolors module is part of the Python Standard Library. True False
False
Using components from the Python Standard Library is a rare occurrence. True False
False
If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n. True False
False Well done! It will produce a result in the range 0 to n-1.
What is syntax coloring? Displaying program output in particular colors Displaying each method of a program in a different color Showing certain elements of program code in different colors Wrapping program output in colored boxes
Showing certain elements of program code in different colors
What does the term case sensitive mean? Each case of a Python print statement must be unique. A Python program must be encased in a human-readable comment. The difference between uppercase and lowercase letters matters. A Python program is enclosed in, and executed relative to, a program case.
The difference between uppercase and lowercase letters matters.
Which of the following statements is true? The print statement is a call to a function. A print statement must be the first statement in a Python program. The print statement sends text output to the editor. The print statement sends text output to a printer.
The print statement is a call to a function.
If a filled shape drawn by a turtle is not fully enclosed, Python fills the shape as if the starting point is connected to the end point. True False
True
If either or both operands to the division operator (//) are floating-point values, then the result will be a floating-point value. True False
True
Setting the turtle's speed to 0 turns off the animation of the turtle movement completely. True False
True
The input function always returns the read data as a character string. True False
True
The math module contains a constant that represents the value pi to several digits. True False
True
The math.pi constant represents pi to 15 decimal places. True False
True
The output of a Python program run in Thonny appears in the shell window. True False
True
The pen color and size determines the color and width of the lines drawn. True False
True
The result of a relational operator can be assigned to a variable. True False
True
Thonny displays code using syntax highlighting. True False
True
Thonny has a package manager that lets you install and update external Python packages. True False
True
Of the options given, what values of the variables height, size, and width would cause the following code to set the variable weight to 100? if height < size: weight = 50 if width < 20: print('short') else: if width > 100: weight = 100 println('tall') height = 12, size = 20, width = 200 height = 15, size = 25, width = 50 height = 15, size = 10, width = 110 height = 20, size = 12, width = 90
height = 15, size = 10, width = 110
Suppose the integer variable hours contains a value that represents a number of hours. Which of the following expressions will compute how many 24-hour periods are represented by that value, without worrying about any leftover hours. hours / 24 + 1 hours % 24 hours // 24 hours / 24
hours // 24
What output is printed by the following code if it is executed when appetizer is 3 and entree is 12? if appetizer > 1: if entree < 7: print('ketchup') else: print('mustard') else: if appetizer < 0: print('mayonnaise') else: print('relish') ketchup mustard mayonnaise relish salsa None of the above
mustard
What output is produced by the following code?print('oak', 'elm', 'pine', end='!', sep='#') oak!elm!pine# oak#!elm#!pine! oak#! elm#! pine#! oak#elm#pine!
oak#elm#pine!
What is the text that requests user input called? poll solicitation cue prompt
prompt