wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Ch. 11 Exam Review

Total questions: 26

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following best describes the index value used to access the very last character in a string?

a)

One less than the length of the string

b)

One more than the length of the string

c)

Equal to the length of the string

d)

Equal to the length of the string divided by two

2.

What is displayed on the output screen when the following code is run? value = "TRUSTWORTHY" print(value[1])

a)

U

b)

T

c)

R

d)

IndexError: string index out of range

3.

What is displayed on the output screen when the following code is run? value = "LOYAL" print(value[5])

a)

IndexError: string index out of range

b)

Y

c)

A

d)

L

4.

What is displayed to the screen when the following code is run? value = "HELPFUL" value = "FRIENDLY" print(value)

a)

HELPFUL

b)

FRIENDLY

c)

Nothing is shown at all

d)

Error: strings are immutable and can't be changed

5.

What is the purpose of calling the len() function and passing in a string?

a)

To chop off the string after a certain length

b)

To extend the string to a specific length

c)

To return the number of characters in the string

d)

This is an error; len() will not work with strings at all

6.

What is wrong with the following statement? print("Yogi Berra said \"A nickle ain't worth a dime anymore.\"")

a)

Nothing is wrong; this quote will print to the screen normally

b)

The double quotes will be silently ignored and the remainder of the text printed to the screen without quotes

c)

Runtime exception - the quote does not match the person that actually said it

d)

Syntax error - you can't directly place a double quote character inside a double-quoted string

7.

What escape sequence is used to embed a new line character within a string value?

a)

\n

b)

\t

c)

%newline

d)

\CR\

8.

When calling a string function in the format str.(), what is always the first parameter inside the parentheses?

a)

A string value on which you want to do some work

b)

The name of the variable that will hold the function output

c)

The length of the string that will follow in the next parameter

d)

A numeric value that will be added to the output at the first placeholder

9.

Which of the following three methods will correctly print the number of "S" characters found in the word "SODAS"? drink = "SODAS" print( str.count(drink , "S") ) # method 1 print( drink.count("S") ) # method 2 print( "SODAS". count("S") ) # method 3

a)

All three will work correctly

b)

Method 1 only

c)

Method 2 only

d)

Method 3 only

10.

What is displayed on the screen when the following code is run? drink = "SODAS" print(str.startswith(drink,"SO"))

a)

True

b)

False

c)

SO

d)

SODAS

11.

What is displayed on the screen when the following code is run? drink = "SODAS" print( str.index(drink,"SS") )

a)

SS

b)

-1

c)

0

d)

Runtime exception - substring not found

12.

Which statement must be included in your Python code in order to use the math library functions?

a)

import math.library

b)

using math.library

c)

import math

d)

include math.library

13.

What is displayed to the output screen when the following code is run? drink = "SODAS" if ("D" in drink): print("I found vitamin D in my soda") else: print("Sodas are not healthy after all")

a)

I found vitamin D in my soda

b)

Sodas are not healthy after all

c)

Nothing is printed

d)

Runtime exception - you can't use the "in" keyword to test for presence of substrings

14.

What is stored in the "drink" variable after the following statement runs? drink = str.lower("SODAS")

a)

sodas

b)

SODAS

c)

Sodas

d)

Nothing (empty string)

15.

Which of the following statements will remove all of the whitespace characters from the ends of the "drink" variable value defined below? drink = " SODAS "

a)

drink = str.strip(drink)

b)

drink = str.whiteout(drink)

c)

drink = tidy(drink)

d)

drink = drink.compact()

16.

Given the "drink" variable defined below, which of the following expressions will evaluate to the substring "DAS"? drink = "SODAS"

a)

drink[2:]

b)

drink.substring(3)

c)

str.split(drink,2)

d)

str.find("DAS")

17.

Which of the following statements will cause a "while" loop to immediately exit without running any more statements in the body or checking the logical expression again?

a)

break

b)

continue

c)

else

d)

stop

18.

Which function will take a string value and convert it to a floating point number, if possible?

a)

int()

b)

float()

c)

convert()

d)

parse()

19.

What is the purpose of using "try" and "except" keywords in your code?

a)

To protect risky statements that might throw an exception and provide a better program response when an exception happens

b)

To identify code that might get stuck in an infinite loop and provide a way of breaking free

c)

To identify code that may run very slowly and give the user some information when that happens

d)

Try / except can be used for all of these cases

20.

Which of the following statements will mark a block of code to run immediately after a try / except sequence, no matter what happens inside those try / except blocks?

a)

finally

b)

else

c)

done

d)

after

21.

Which statement might you use after a try / except sequence if you want to print a confirmation message when the user has entered a valid value without any exceptions?

a)

else

b)

finally

c)

normal

d)

after

22.

If a user input was successfully converted to an integer value and stored in the "answer" variable, which of the following statements would help verify that answer was between 1 and 10?

a)

if (answer >= 1) and (answer <= 10):

b)

if valid(answer,1,10):

c)

if (answer == 1) or (answer == 10):

d)

if (answer in range(1,10)):

23.

Given the following code, how many times will the "while" loop body execute?

a)

Infinite loop

b)

0

c)

2

d)

4

24.

A collection of useful functions is commonly called a _______________.

a)
library
b)
set
c)
group
d)
node
25.

Given a list named "mystery", which of the following expressions will return a random element in that list?

a)

mystery.choice()

b)

mystery.random()

c)

random(mystery)

d)

random.choice(mystery)

26.

Using built-in Python modules forces a programmer to re-create functions to handle common tasks.

a)

True

b)

False