wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

COMP I77 Module 2 Quiz

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

A is a named item used to hold a value.

a)

constant

b)

number

c)

statement

d)
variable
2.

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

3.

What is the value of y after the following code is executed? Note that the question asks for y, not x.

X=10

y= x+2

x = 12

a)

8

b)

10

c)

12

d)

14

4.

Which of the following symbols can be used as part of an identifier?

a)

@

b)

$

c)

&

d)

(underscore)

5.

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

6.

is the process where objects that are no longer needed are deleted.

a)

Identity recycling

b)

Memory clearing

c)
Garbage collection
d)

Object recycling

7.

Objects like integers and strings that can't be modified are called _____.

a)

immutable

b)

mutable

c)

frozen

d)

set

8.

The built-in Python function that gives an object's identity is:

a)

memory()

b)

id()

c)

type()

d)

identity()

9.

What is the name of the data type used for floating point numbers?

a)

float

b)

decimal

c)

non_integer

d)

floating_point

10.

In Python, which of the following literals is shown in valid scientific notation?

a)

3.0004e-12

b)

17.012s14

c)

0.003×10^-5

d)

e12f3.04

11.

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)

12.

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

13.

The operator *= is called a(n) ____ operator.

a)

A. double

b)

B. compound

c)

C. increment

d)

D. multiple assignment

14.

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

15.

15 3 = 5.0

a)

%

b)

^

c)
/
d)

//

16.

What is the value of 11 // 2?

a)

5

b)

6

c)

0

d)

3

17.

Which statement makes the code in the math module available?

a)

use math

b)

allow math

c)

import math

d)

include math

18.

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)

19.

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__

20.

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)

21.

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

22.

What does print("one\two\three") display?

a)

one\\two\\\three

b)

one\two\\three

c)

one twothree

d)

one\\\\two\\\\\\three

23.

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))

24.

Which print statement would display 'C:\Users\Mika\grades.txt' (without the single quotes)?

a)

printr('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')

25.

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!')