Python Week 4
False
A character encoding is the list of all characters used by a programming language.
True
A for loop is a good way to access each character in a string.
False
A nested loop is required to draw a squared-corner spiral.
5
How many times will the following code print the word 'wow'? for val in range(5, 10): print('wow')
True
In some cases, a sentinel value can be used to signal the end of input.
False
In the High-Low program, it's impossible for the user to guess the target value in one guess.
False
In the High-Low program, the number of times the while loop will be executed can be calculated before the loop begins.
True
Python uses the Unicode character set to represent characters.
True
The High-Low program would still work if the initial value of guess were set to -1 instead of -999.
False
The Olympic rings program uses a loop to draw the five rings.
True
The Python for loop is what other languages refer to as a for-each loop.
True
The Unicode character set currently represents over 100,000 characters.
False
The body of a for loop cannot contain another for loop.
True
The body of a while loop may never execute.
False
The choice function in the random module lets you choose multiple elements from a list.
6 to 12
The expression random.randint(6, 12) will produce a value in what range?
0 to 29
The expression random.randrange(30) will produce a value in what range?
5 to 9
The expression random.randrange(5, 10) will produce a value in what range?
False
The if statement in the High-Low program had to be written so that it checks for the correct guess last.
True
The loop in the curved spiral program controls both how many lines are drawn and how long each one is.
False
The loop in the star program controls how long each line in the star is.
False
The random values used in the starbursts program were all determined by calls to the randint function from the Python Standard Library.
False
The sample function in the random module takes a sample with replacement.
False
The start value passed as an argument to the range function cannot be negative.
False
There is no way to stop an infinite loop.
True
Using a while loop to check each input value for correctness is a form of input validation.
A loop condition that is never false.
What causes an infinite loop?
A subset of Unicode containing primarily English characters and basic symbols.
What is ASCII?
lexicographic ordering
What technique is used to put Unicode characters and strings in order?
24
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
random.randrange(1, 11)
Which of the following expressions would produce a value in the range 1 to 10?
if statement
Which of the following is NOT a repetition statement in Python? if statement
12 10 8 6
Which range is produced by the function call range(12, 5, -2)?
4 5 6 7 8 9
Which range is produced by the function call range(4, 10)?
0 1 2 3 4
Which range is produced by the function call range(5)?
The one that points southeast.
In the flower design program, which diamond is drawn first?
False
In the honeycomb program, the draw_hexagon function is called seven times.
True
In the honeycomb program, the draw_honeycomb function calls the draw_hexagon function.
False
In the random turtle walk program, the loop control variable is used to determine whether the turtle turns right or left.
False
In the starbursts program, the number of starbursts drawn is determined randomly.
False
The step value passed as an argument to the range function cannot be negative.
True
The stop value passed as an argument to the range function is NOT included in the range produced.
It's a number that is the basis of the calculated pseudorandom numbers.
What is the role of the seed value of a random number generator?
Num: 2
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)