Week 3
The expression random.randrange(30) will produce a value in what range?
0 to 29
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!')
13
Which of the following statements is true?
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.
A character string can be used as the condition of an if statement.
True
An entire module can be imported using one import statement.
True
An import statement finds a module and binds it to a name you can use in a program.
True
Built-in functions of the Python Standard Library can be used without being imported.
True
Full documentation about the Python Standard Library can be found online.
True
If A and B are both false, then the expression A and B is false.
True
If A is false, then the B operand in the expression A and B is not evaluated.
True
If A is true and B is false, then the expression A or B is true.
True
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
In Python, the relational operators can be used to put character strings in alphabetical order.
True
The relational operators all return boolean results.
True
The result of a relational operator can be assigned to a variable.
True
Two functions can have the same name if they are in different modules.
True
When using relational operators to compare character strings, 'Music' comes before 'music'.
True
What is the Python Standard Library?
A collection of programming components that can be used in any Python program.
An if statement cannot have both an elif and an else clause.
False
Functions of the math module do not have to be imported.
False
If A is false, then the B operand in the expression A or B is not evaluated.
False
Strings containing non-alphabetic characters cannot be compared using the relational operators.
False
The arithmetic operators have a lower precedence than the relational operators.
False
The choice function in the random module lets you choose multiple elements from a list.
False
The from clause of an import statement lets you define an alias for a module or function.
False
The less than operator (<) should not be used to compare floating point values.
False
The not operator requires two operands.
False
The sample function in the random module takes a sample with replacement.
False
Using components from the Python Standard Library is a rare occurrence.
False
When using relational operators to compare character strings, 'ZEBRA' comes before 'ALLIGATOR'.
False
What is the role of the seed value of a random number generator?
It's a number that is basis of the calculated pseudorandom numbers.
What is lexicographic ordering?
Ordering characters based on a character set
Which of the following conclusions is NOT true when using relational operators to compare character strings?
fantastic comes before Great
Of the options given, what values of the variables height, size, and widthwould 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 = 15, size = 10, width = 110
What output is printed by the following code if it is executed when appetizeris 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')
mustard
Which of the following expressions would produce a value in the range 1 to 10?
random.randrange(1, 11)
Which of the following conclusions is NOT true when using relational operators to compare character strings?
reset comes before reserve
The expression random.randrange(5, 10) will produce a value in what range?
5 to 9
The expression random.randint(6, 12) will produce a value in what range?
6 to 12
Which of the following is a relational operator?
<=
Which of the following expressions could be used to determine if a is not less than b?
a >= b
