NEW
Font size
WorksheetsCh. 11 Exam Review
Total questions: 26
Worksheet time: 13mins
Which of the following best describes the index value used to access the very last character in a string?
One less than the length of the string
One more than the length of the string
Equal to the length of the string
Equal to the length of the string divided by two
What is displayed on the output screen when the following code is run? value = "TRUSTWORTHY" print(value[1])
U
T
R
IndexError: string index out of range
What is displayed on the output screen when the following code is run? value = "LOYAL" print(value[5])
IndexError: string index out of range
Y
A
L
What is displayed to the screen when the following code is run? value = "HELPFUL" value = "FRIENDLY" print(value)
HELPFUL
FRIENDLY
Nothing is shown at all
Error: strings are immutable and can't be changed
What is the purpose of calling the len() function and passing in a string?
To chop off the string after a certain length
To extend the string to a specific length
To return the number of characters in the string
This is an error; len() will not work with strings at all
What is wrong with the following statement? print("Yogi Berra said \"A nickle ain't worth a dime anymore.\"")
Nothing is wrong; this quote will print to the screen normally
The double quotes will be silently ignored and the remainder of the text printed to the screen without quotes
Runtime exception - the quote does not match the person that actually said it
Syntax error - you can't directly place a double quote character inside a double-quoted string
What escape sequence is used to embed a new line character within a string value?
\n
\t
%newline
\CR\
When calling a string function in the format str.
A string value on which you want to do some work
The name of the variable that will hold the function output
The length of the string that will follow in the next parameter
A numeric value that will be added to the output at the first placeholder
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
All three will work correctly
Method 1 only
Method 2 only
Method 3 only
What is displayed on the screen when the following code is run? drink = "SODAS" print(str.startswith(drink,"SO"))
True
False
SO
SODAS
What is displayed on the screen when the following code is run? drink = "SODAS" print( str.index(drink,"SS") )
SS
-1
0
Runtime exception - substring not found
Which statement must be included in your Python code in order to use the math library functions?
import math.library
using math.library
import math
include math.library
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")
I found vitamin D in my soda
Sodas are not healthy after all
Nothing is printed
Runtime exception - you can't use the "in" keyword to test for presence of substrings
What is stored in the "drink" variable after the following statement runs? drink = str.lower("SODAS")
sodas
SODAS
Sodas
Nothing (empty string)
Which of the following statements will remove all of the whitespace characters from the ends of the "drink" variable value defined below? drink = " SODAS "
drink = str.strip(drink)
drink = str.whiteout(drink)
drink = tidy(drink)
drink = drink.compact()
Given the "drink" variable defined below, which of the following expressions will evaluate to the substring "DAS"? drink = "SODAS"
drink[2:]
drink.substring(3)
str.split(drink,2)
str.find("DAS")
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?
break
continue
else
stop
Which function will take a string value and convert it to a floating point number, if possible?
int()
float()
convert()
parse()
What is the purpose of using "try" and "except" keywords in your code?
To protect risky statements that might throw an exception and provide a better program response when an exception happens
To identify code that might get stuck in an infinite loop and provide a way of breaking free
To identify code that may run very slowly and give the user some information when that happens
Try / except can be used for all of these cases
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?
finally
else
done
after
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?
else
finally
normal
after
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?
if (answer >= 1) and (answer <= 10):
if valid(answer,1,10):
if (answer == 1) or (answer == 10):
if (answer in range(1,10)):
Given the following code, how many times will the "while" loop body execute?
Infinite loop
0
2
4
A collection of useful functions is commonly called a _______________.
Given a list named "mystery", which of the following expressions will return a random element in that list?
mystery.choice()
mystery.random()
random(mystery)
random.choice(mystery)
Using built-in Python modules forces a programmer to re-create functions to handle common tasks.
True
False
