Midterm 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

8) Which of the following symbols can be used as part of an identifier? a. @ b. $ c. & d. _ (underscore)

d. _ (underscore)

20) The operator *= is called a(n) _____ operator. a. double b. compound c. increment d. multiple assignment

d. multiple assignment

35) Which print statement would display: I won't quit! a. print('I won\\'t quit!') b. print('I won't quit!') c. print('I won\'\t quit!') d. print('I won\'t quit!')

d. print('I won\'t quit!')

37) Which print statement would display 'C:\Users\Mika\grades.txt' (without the single quotes)? a. print(r'C:\/Users\/Mika\/grades.txt') b. print(r'C:\'Users\'Mika\'grades.txt') c. print(r'C:\Users\Mika\grades.txt') d. print(r'C:\\Users\\Mika\\grades.txt')

d. print(r'C:\\Users\\Mika\\grades.txt')

25) Which expression gives the number of whole minutes that corresponds to some number of seconds? a. seconds % 60 b. seconds / 60 c. seconds * 60 d. seconds // 60

d. seconds // 60

Here are some questions related to this Module topic. These questions are not graded, nor need to be submitted. They are made just for you as extra questions to test your understanding of this module. 1) A _____ is a named item used to hold a value. a. constant b. number c. statement d. variable

d. variable

17) According to Python's precedence rules, which of the following operators has the highest precedence? a. subtraction - b. unary - c. * d. +

unary -

21) Which statement is equivalent to the following assignment? x -= 2 + y a. x = 2 + y - x b. x = -(2 + y) c. x = x - (2 + y) d. x = x - 2 + y

x = x - (2 + y)

4) What is the value of x after the following code is executed? x = 15x = x + 1x = x * 2x = 30 - x a. -2 b. 2 c. 15 d. 32

2

24) 15 _____ 3 = 0 a. % b. / c. // d. *

a. %

22) Which floating-point literal correctly represents the scientific notation value: 2.3 x 10^7? a. 2.3e7 b. 2.3*10e7 c. 2.3e10^7 d. 2.3xe7

a. 2.3e7

14) In Python, which of the following literals is shown in valid scientific notation? a. 3.0004e-12 b. 17.012s14 c. 0.003x10^-5 d. e12f3.04

a. 3.0004e-12

26) What is the value of 11 // 2? a. 5 b. 6 c. 0 d. -5

a. 5

29) What is the value of the __name__ built-in variable in a module that is executed as a script by the programmer? a. __main__ b. __direct__ c. __module__ d. __executed__

a. __main__

30) An item passed to a function is a(n) _____ . a. argument b. instruction c. call d. module

a. argument

12) What is the name of the data type used for floating point numbers? a. float b. decimal c. non_integer d. floating_point

a. float

6) Objects like integers and strings that can't be modified are called _____ . a. immutable b. mutable c. frozen d. set

a. immutable

10) A _____ is a word that is part of the Python language and can't be used as a variable name. a. keyword b. special token c. syntax symbol d. stylized word

a. keyword

11) Which of the following identifiers is valid? a. max_age b. 32area c. transfer$ d. True

a. max_age

28) Which print statement displays the value of a variable called argv in a module called sys? a. print(argv in sys) b. print(sys.argv) c. print(sys_argv) d. print(module sys var argv)

a. print(argv in sys)

36) Which print statement would display the letter 'A'? (Note that the code point for the letter 'A' is 65.) a. print(chr(65)) b. print(ord(65)) c. print(unicode(65)) d. print(code_point(65))

a. print(chr(65))

3) Which of the following statements has a syntax error? Assume age and years are variables that have already been defined. a. age = years - 2 b. age + 2 = years c. age = 17 - 2 d. age = -15

b. age + 2 = years

9) A language is called _____ when upper case letters in identifiers are considered different from lower case letters. a. unambiguous b. case sensitive c. case strict d. camel case

b. case sensitive

33) The special two-item character sequence that represents special characters like \n is known as a(n) _____. a. backslash code b. escape sequence c. unicode spec d. literal character

b. escape sequence

7) The built-in Python function that gives an object's identity is: a. memory() b. id() c. type() d. identity()

b. id()

19) The formula for calculating the amount of interest charged on a loan is: interest = [principal x rate] of interest x time Which Python statement correctly performs the interest calculation? a. interest = [principal * rate_of_interest] * time b. interest = principal * rate of interest * time c. interest = principal x interest x time d. interest = (principal * interest) * time

b. interest = (principal * interest) * time

34) What does print("one\\two\\\\three") display? a. one\\two\\\three b. one\two\\three c. one twothree d. one\\\\two\\\\\\\\three

b. one\two\\three

15) Assigning a value to a floating point variable that is too large for the computer to represent is a condition called _____ . a. bit error b. overflow c. overcapacity d. system error

b. overflow

18) Which expression using parentheses is equivalent to the following expression: x - y * -z / 3 a. (x - y) * ((-z) / 3)) b. x - ((y * (-z)) / 3) c. x - (y * ((-z) / 3)) d. (x - (y * (-z))) / 3

b. x - ((y * (-z)) / 3)

32) What is the ending value of z? x = 0.3z = math.pow(math.ceil(x), 2) a. 0.0 b. 0.09 c. 1.0 d. 1.09

c. 1.0

2) 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 a. 8 b. 10 c. 12 d. 14

c. 12

16) Which of the following is not a valid expression? Assume x and y are integer variables. a. x / (y * 7) b. y / x * 2 c. 2x + 3y d. (x - 3*y)

c. 2x + 3y

5) _____ is the process where objects that are no longer needed are deleted. a. Identity recycling b. Memory clearing c. Garbage collection d. Object recycling

c. Garbage collection

27) Which statement makes the code in the math module available? a. use math b. allow math c. import math d. include math

c. import math

31) 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? a. math.square_root(a * a + b * b) b. math.sqrt(math.pow(a * a), math.pow(b * b)) c. math.sqrt(math.pow(a, 2)) + math.pow(b, 2))) d. math.pow(math.sqrt(a), 2) + math.pow(math.sqrt(b), 2)

c. math.sqrt(math.pow(a, 2)) + math.pow(b, 2)))

23) 15 _____ 3 = 5.0 a. % b. ^ c. / d. //

d. //

1) Which statement assigns the string variable airport_code with the value JFK? a. airport_code = 'JFK' b. airport_code = JFK c. 'JFK' = airport_code d. JFK = 'airport_code'

d. JFK = 'airport_code'

13) Which of the following data values is best represented with a floating point variable? a. The number of pets in a house. b. The number of acorns in a tree. c. The number of children in a classroom. d. The speed of a snail.

d. The speed of a snail


Conjuntos de estudio relacionados

Molecular Cell Bio Test IV: Clicker Question

View Set

Fritsch US History: LAP 11 (COMPLETE)

View Set

Chapter 5: Morphology and Syntax in the Preschool Years

View Set

Organizational Behavior Chapter 6

View Set