Consider this Python code: balance = 100; balance = balance - 25; balance = balance + 10. After all three statements execute, is balance equal to 85?
02 Variables, Expressions, and Input/Output Online Quiz Questions
Use this free practice quiz with 20 questions to review 02 Variables, Expressions, and Input/Output, test your knowledge, and prepare for your next test or exam.
Which item is an integer literal in Python?
- A
answer - B
42 - C
value - D
number
What type of value does Python's input() function return before any conversion?
Complete the statement: In Python, the operator that assigns a value to a variable is .
What value is assigned to result by this statement: result = 2 + 3 * 4?
- A
10
- B
20
- C
14
- D
24
True or false: In Python, assigning a new value to an uppercase constant name always causes an error.
- A
True
- B
False
Which operations are demonstrated by this data flow: receive a number as text, convert it to an integer, store the result, and display it? Select all four correct choices.
- A
Reading a response with input()
- B
Displaying text with print()
- C
Converting text with int()
- D
Storing a result through assignment
- E
Merely writing an expression without using its result
What is the name of the arithmetic operation performed by the Python operator //?
Complete the statement: A Python string written with a leading f so that expressions can be evaluated inside braces is called an .
Which expression tests whether the variable score has the value 100?
- A
score = 100 - B
score == 100 - C
score != 100 - D
score + 100
Which three statements accurately describe common issues or safeguards when using Python input? Select all correct choices.
- A
Two unconverted numeric inputs can be concatenated instead of added.
- B
input()automatically returns an integer when the user enters digits. - C
int()can convert suitable numeric text for arithmetic. - D
Every text response can be converted successfully with
int(). - E
A conversion can fail when the text does not have the expected numeric format.
What value does count have after this code executes? count = 5; count += 2; count *= 3.
- A
15
- B
17
- C
21
- D
7
Trace this Python code and state the final values of subtotal, tax, and total, explaining how each value is produced: TAX_RATE = 0.08; price = 12; quantity = 3; subtotal = price * quantity; tax = subtotal * TAX_RATE; total = subtotal + tax.
What value is assigned to remainder by this Python statement: remainder = 17 % 5?
- A
3
- B
12
- C
2
- D
5
True or false: The Python statement x = x + 1 is valid when x already has the value 4, and afterward x has the value 5.
- A
True
- B
False
Which statement best describes the conventional use of uppercase names such as TAX_RATE in Python?
- A
Python prevents any later assignment to an uppercase name.
- B
An uppercase name communicates that the program intends the value not to change.
- C
Only string values can be assigned to uppercase names.
- D
An uppercase name automatically creates a special constant object.
What value is assigned to result by this statement?
result = 2 + 3 * 4
- A
10
- B
20
- C
14
- D
24
What is the final value of balance after this code executes?
balance = 100
balance = balance - 25
balance = balance + 10
Suppose score = 100. What does is_perfect = (score == 100) do?
- A
It increases
scoreby 100. - B
It tests whether
scoreequals 100 and stores the Boolean result. - C
It changes the type of
scoreto Boolean without testing it. - D
It tests whether
scoreis greater than 100.
Which Python function converts numeric text into an integer?