NEW
Font size
WorksheetsCh. 5 Exam Review
Total questions: 25
Worksheet time: 13mins
If you concatenate strings together with the plus sign (+), which of the following statements is true?
No spaces will be added to separate the parts within the output string
A space will be automatically added to separate each part within the output string
Only the longer input string will appear in the output string
The resulting string must be less than 128 characters in length
When you use the print() statement to automatically concatenate multiple parameters together, which of the following statements is true?
No spaces will be added to separate the parts within the output string
A space will be automatically added to separate each part within the output string
Only the first parameter will be present in the output string
The resulting string must be less than 128 characters in length
What is the output when the following statements are run? favoriteColor = "purple" print("My favorite color is", favoriteColor)
purple
My favorite color ispurple
My favorite color is favoriteColor
My favorite color is purple
What is the output when the following statements are run? accountBalance = 112.5 print("My balance is: $", accountBalance)
$ 112.5
My balance is: $ accountBalance
My balance is: $ 112.5
You will see an error because you can't use a numeric parameter inside print()
Which answer shows the output from the following print() statement? print("If you can dream it", "you can do it.", sep="#")
If you can dream it#you can do it.
If you can dream it, you can do it.
If#you#can#dream#it#you#can#do#it.
you can do it.#sep#If you can dream it
How many lines of output will be shown from the following code? print("Line 1", end = " ") print("Line 2") print("Line 3", end = " ")
1
2
3
0
Which of the following two statements about the print() function are true?
print() with multiple parameters will automatically convert all values to strings and join them together with a space
print() with a single string parameter will display the exact string that you pass in
Both of these are true
Neither of these is true
What type of data does the input() function return?
String
Integer
Floating point
It depends on what the user types in
Which of the following best describes the input() parameter?
It contains a text prompt for the user to enter a value
It contains the length of time the function will wait for an answer
It contains the name of the variable that will hold the output
It contains the number of values the user must enter
If the user enters "18" in response to an input() question, what kind of data is returned?
An integer containing 18
A string containing "18"
A floating point containing 18.0
A "True" Boolean value showing success
Which of the following statements will successfully prompt the user for input and store the result in the "answer" variable?
input.answer("What is your quest?")
answer("What is your quest?")
answer = parse(What is your quest?)
answer = input("What is your quest?")
Which of the following statements will convert a string stored in "inputResults" to an integer variable called "age"?
age = int(inputResults)
age.int(inputResults)
inputResults = parse(age)
age = inputResults.parse()
Which function would you use to convert a string value to a floating point value?
int()
parse()
float()
decimal()
What will happen when the following statements run? value = "orange" result = int(value)
You will see a ValueError message due to invalid int() input
The result variable will contain 0
The result variable will contain the length of the string stored in the value variable
Both value and result variables will be set to 0
How many input parameters are provided to the str.format() function?
3 only
1 only
1 or more as needed to build your output string
None
How many additional str.format() parameters are expected if the format string parameter contains "Happy birthday {}, happy birthday to you"?
1
2
3
0
What string value is stored in the answer variable after the following statement is run? answer = str.format("{2} {1} {0}", "with","great","power")
power great with
with great power
great power with
power power power
How would you create a str.format() placeholder in the format string to ensure at least 20 characters minimum width for the first value?
0{20}
[20:0]
{0:20}
{:20.0}
Which of the following placeholder expressions in a str.format() format string will limit (truncate) the width of an output value to 10 characters?
{:5.10}
[:10.5]
{5:10}
{5,10}
What is the output from the following statement? print(str.format("Sale Price: ${:0,.}",1500))
Sale Price: $ 1,500
Sale Price: $ 1500
Sale Price: $ 0
Sale Price: $ ValueError
Which vocabulary word means: To join two or more smaller strings into a single larger string value.
Truncate
Concatenation
Alignment
Event
Which vocabulary word means: Data that is returned from a function back to the main program or from a program to the user.
Output Data
Truncate
Input Data
Event
Which vocabulary word means: Data that is passed into a program or function that can be used to guide the program's behavior or output.
Output Data
Truncate
Input Data
Event
Which vocabulary word means: A user action that occurs in a program.
Output Data
Truncate
Input Data
Event
Which vocabulary word means: To clip or cut short a value or string after a certain number of characters or digits.
Output Data
Truncate
Input Data
Alignment
