COMP 163 (Chapter 2)
Which of the following symbols can be used as part of an identifier?
_ (underscore)
An item passed to a function is a(n) _____ .
argument
What is the value of x after the following code is executed?
-2
What is the value of x after the following code is executed? x = 15x = x + 1x = x * 2x = 30 - x
-2
What are the possible values for random.randint(-4, 4)?
-4...4
15 _____ 3 = 5.0
/
What are the possible values for random.randrange(6)?
0...5
What is the value of y after the following code is executed? Note that the question asks for y, not x. x = 10y = x + 2x = 12
12
Which floating-point literal correctly represents the scientific notation value: 2.3 x 10^7?
2.3e7
Which of the following is not a valid expression? Assume x and y are integer variables.
2x + 3y
The built-in Python function that gives an object's identity is:
id()
Objects like integers and strings that can't be modified are called _____ .
immutable
A _____ is a word that is part of the Python language and can't be used as a variable name.
keyword
Assume a and b are variables that hold the base and height of a right triangle. The length of the long side (hypotenuse) is calculated as the square root of a^2 + b^2. Which expression calculates the length of the hypotenuse?
math.sqrt(math.pow(a, 2) + math.pow(b, 2))
What does print("one\\two\\\\three") display?
one\two\\three
Which print statement would display the letter 'A'? (Note that the code point for the letter 'A' is 65.)
print(chr(65))
Which print statement would display 'C:\Users\Mika\grades.txt' (without the single quotes)?
print(r'C:\Users\Mika\grades.txt')
Which print statement displays the value of a variable called argv in a module called sys?
print(sys.argv)
Dice have 6 sides, with values 1, 2, 3, 4, 5, and 6. Which expression randomly rolls one dice, directly yielding one of those values?
random.randint(1, 6)
Which generates a random integer in the range 13...19 (inclusive)?
random.randrange(19 - 13 + 1) + 13
Which expression is most appropriate for randomly choosing a day of the week?
random.randrange(7)
Which expression gives the number of whole minutes that corresponds to some number of seconds?
seconds // 60
According to Python's precedence rules, which of the following operators has the highest precedence?
unary -
A _____ is a named item used to hold a value.
variable
Which statement is equivalent to the following assignment?
x = x - (2 + y)
Which statement is equivalent to the following assignment? x -= 2 + y
x = x - (2 + y)
A language is called _____ when upper case letters in identifiers are considered different from lower case letters.
case sensitive
The operator *= is called a(n) _____ operator.
compound
The special two-item character sequence that represents special characters like \n is known as a(n) _____.
escape sequence
What is the name of the data type used for floating point numbers?
float