wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python CH1-3 Review

Total questions: 59

Worksheet time: 36mins

Name
Class
Date
1.

Which of the following are ways you can run a Python program?

a)

Double clicking on the file directly

b)

Opening the file in IDLE and clicking “Run Module”

c)

Running the program through Command Prompt or terminal

d)

All the above

2.

What is the file extension used for Python scripts?

a)

.py

b)

.p

c)

.python

d)

.ps

3.

You have a variable named “True” and Python gives you an error. What’s the problem?

a)

The “T” should be lower-case

b)

“True” is a reserved keyword used by Python

c)

Every letter must be capitalized

d)

It’s correct. There is some other problem in the script

4.

The modulo operator uses what symbol?

a)

**

b)

//

c)

%

d)

^

5.

Python comments are denoted by what symbol?

a)

#

b)

//

c)

/*

d)

$

6.

x = True, y = False

What is the value of the expression not x?

a)

True

b)

False

7.

x = True, y = False

What is the value of the expression y and not x?

a)

True

b)

False

8.

x = True, y = False

What is the value of the expression not x or not y?

a)

True

b)

False

9.

x = True, y = False

What is the value of the expression not( x and y )?

a)

True

b)

False

10.

Which of the following is the proper way to write the string: “Hello, world!”?

a)

A. "Hello, world!"

b)

B. 'Hello, world!'

c)

C. "Hello, world!'

d)

Both A & B

e)

A, B, and C

11.

What common Python function is used to display text to the screen?

a)

display

b)

output

c)

print

d)

show

12.

You have the following line in your script:

number_of_apples = number_of_apples + 1

How would you rewrite this expression in shorthand?

a)

number_of_apples++

b)

number_of_apples += 1

c)

number_of_apples =+ 1

d)

number_of_apples+1

13.

What is the convention for naming a constant?

a)

Write it in all capital letters

b)

Capitalize the first letter

c)

Start the name with const_

d)

Start it with a dollar sign

14.

Observe the following code:

word1 = "hello" word2 = "world" string = word1 + word2 * 2

What is the value of variable string?

(A ‘_’ represents a space)

a)

helloworld

b)

hello_world_world

c)

helloworldworld

d)

helloworldhelloworld

15.

The (a)   data type represents true or false.

16.

If a variable name uses multiple words, you should separate them using underscores or write it in (a)   .

17.

Strings are a collection of (a)   , such as letters, numbers, or symbols.

18.

(a)   is where you convert a value to a different data type, such as an integer to a float.

19.

True/False: Code blocks are always indented.

(a)  

20.

True/False: Else statements do not require an if statement before it.

(a)  

21.

True/False: Strings are immutable, which means that they can change.

(a)  

22.

True/False: A for loop runs for a certain number of times.

(a)  

23.

You are trying to get an integer from the user’s input and save it to the variable x. Which of the following will accomplish the task?

a)

x = input("Enter a number: ")

b)

x = int(input("Enter a number: ")

c)

Both A & B

d)

Neither A nor B

24.

Which of the following can be used to represent a multi-line string? Select all that apply.

a)

"

b)

""

c)

"""

d)

'''

25.

Observe the following line of code:

string = "No one expects... ____ the Spanish inquisition!"

Which escape sequence will correctly put a line-break where the “____” is?

a)

\n

b)

\nl

c)

\lb

d)

\r

26.

Observe the following code segment:

x = 0 while x <= 10:

print(x) x += 2

How many times will the while loop run?

a)

5

b)

6

c)

10

d)

11

27.

Observe the following code segment:

num = 4

if num <= 4 and num + 1 != 5:

print("A")

elif num < 4:

print("B")

print("C")

What is the final output?

a)

C

b)

B

c)

A

d)

AB

e)

AC

28.

Observe the following incomplete code segment:

string = "Hello, world!"

___________________:

print(letter)

You are wanting to print each letter of string on its own line. Which of the following statements would correctly do this if put on the blank line?

a)

for letter in string

b)

for string as letter

c)

while letter in string

d)

while letter != len(string)

29.

When using format on a string, which of the following represents a placeholder for a value?

a)

{ }

b)

[ ]

c)

( )

d)

< >

30.

Observe the following code segment:

for x in range(__,__):

print(x)

What two values (starting and finishing) for range would cause the loop to iterate exactly ten times? Select all that apply.

a)

0, 10

b)

1, 11

c)

0, 9

d)

0, 11

31.

(a)   gets a portion of a string; also called a substring.

32.

Observe the following code:

strA = "Hello"

strB = "World"

strC = strA + strB * 3

x = len(strC)

What is the value of x at the end of execution?

a)

5

b)

10

c)

20

d)

25

33.

In Python, what do we use to start a code block?

a)

colon

b)

quotes

c)

forward slash

d)

question marks

34.

A Code Block is: (Choose all that apply)

a)

A collection of lines of codes

b)

Always indented

c)

Never indented

d)

Allowed to be typed how the programmer feels works best

35.

What allows code to go down different paths based on Boolean expressions?

a)

Conditional statement

b)

False statement

c)

True statement

d)

Factual statement

36.

What has to happen for an else statement to wok properly? (Choose Two)

a)

It has to have an if statement before it.

b)

the condition has to fail.

c)

the condition has to be true.

d)

it takes the place of an if statement.

37.

An if statement checks if something is:

a)

true

b)

false

38.

How many if statements can we put into a code, as long as we are entering them properly?

a)

As many as you want

b)

3

c)

5

d)

1

39.

What does elif mean?

(a)  

40.

What best describes an input?

a)

A pause in the function until the user types in something and hits enter.

b)

A section of the program that prints a value.

c)

A pause in the program until the computations are completed.

d)

An area of code that requires the program itself to enter something and hit enter.

41.

Format function allows us to format:

a)

Strings

b)

Integers

c)

Variables

d)

Parameters

42.

If I am formating a string, how do I align the text to the center:

a)

{:<n}

b)

{:^n}

c)

[:^n]

d)

{:n}

43.

If I am formating for percision, which means how many spaces tshould the text take up, I will use:

a)

{:n}

b)

{:.nf}

c)

[:n]

d)

{:<n}

44.

An input function will only return what as a variable?

a)

String

b)

Boolean

c)

Float

d)

Integer

45.

What are two special parameters mentioned today?

a)

sep

b)

end

c)

start

d)

quotes

46.

Sep will allow you to:

a)

Print values between each item.

b)

Specify which item will be at the end.

47.

What function will show zero or more things that are separated by a comma?

a)

Print

b)

Function

c)

Show

d)

Variable

48.

What do we need to use to show that something is a parameter?

a)

colon

b)

comma

c)

parenthesis

d)

quotes

49.

Which operator means power:

a)

+

b)

-

c)

*

d)

//

e)

**

50.

x=True, y=False

What is the value of the expression: not x

a)

True

b)

False

51.

x=True, y=False

What is the value of the expression: x or y

a)

True

b)

False

52.

Which comparison Operator means not equal to:

a)

!=

b)

=!

c)

==

d)

=/=

53.

What is the main purpose for using Assignment Operators?

a)

Shorthand for longer expressions

b)

Simple Assignment

c)

Assigning a value to the variable

d)

SO MUCH MATH

54.

In Python, there are four groups of operators:

a)

Calculations

b)

Comparison

c)

Assignment

d)

Logical

e)

Answers

55.

True/False: Make sure your whitespace is used sparingly, only use it to really show what the string is doing.

(a)  

56.

A while loop will keep running as long as something is:

a)

True

b)

False

57.

A (a)   is a name that refers to a value.

58.

Reserved words, known as keywords, cannot be used for variable names.

a)

True

b)

False

59.

What comes installed with Python?

a)

IDLE

b)

IDOL

c)

VMware

d)

Nothing