A Python program contains age = input("Age: "). What is required before the program can safely evaluate age + 1 as numerical addition?
02. Variables, Data Types, and Input–Output Online Quiz Questions
Use this free practice quiz with 20 questions to review 02. Variables, Data Types, and Input–Output, test your knowledge, and prepare for your next test or exam.
Select all the valid Python identifiers from the following choices.
- A
first_name - B
2nd_place - C
_count2 - D
return
True or false: In Python, the statement score = 100 tests whether score is equal to 100.
- A
True
- B
False
What Python type name is produced by evaluating type(float("3.5")).__name__?
A is a named reference to a value that a program can store and use later.
True or false: Python uses uppercase naming as a convention for constants, but it still technically allows the name to be reassigned.
- A
True
- B
False
If x is initially 4, what is the value of x after Python executes x = x + 1?
- A
It compares
xwithx + 1. - B
It creates a new variable named
x + 1. - C
It increases the current value of
xby 1 and stores the result inx. - D
It causes an error because a variable cannot appear on both sides.
Select all the expressions that perform a successful explicit type conversion based on the material.
- A
int("42") - B
str(2026) - C
int("hello") - D
input("Enter a number: ")
Enter the integer result of evaluating int(-7.9) in Python.
In the input–process–output pattern, the program first receives data as and later reports the result as .
Consider this code:
length = float(input("Enter the rectangle's length: "))
width = float(input("Enter the rectangle's width: "))
area = length * width
print(f"The area is {area:.2f} square units.")
If the user enters 8 and then 5, what line is displayed?
- A
The area is 40 square units. - B
The area is 40.0 square units. - C
The area is 40.000 square units. - D
The area is 40.00 square units.
Explain what happens when Python executes print(total) if no earlier statement has assigned a value to total, and state one way to correct the problem.
Which revision correctly allows a program to read a user's age and print the age one year later?
- A
age = input("Age: ")followed byprint(age + 1) - B
age = int(input("Age: "))followed byprint(age + 1) - C
age = str(input("Age: "))followed byprint(age + 1) - D
age = bool(input("Age: "))followed byprint(age + 1)
After this Python code runs, what value does score have?
score = 80
score = 95
- A
80
- B
95
- C
175
- D
An error occurs because score cannot be reassigned
Which of the following is a valid Python identifier?
- A
2student_name - B
class - C
student_name - D
student-name
What are the values of x and y after this Python code runs?
x, y = 10, 20
x, y = y, x
- A
x = 10, y = 20 - B
x = 20, y = 10 - C
x = 10, y = 10 - D
The statement produces a syntax error
True or false: In Python, writing a constant name in uppercase prevents the program from reassigning that value.
- A
True
- B
False
What integer does Python return for int(-7.9)?
What Python function reads a line from the user and returns the entered data as a string?
A user enters 8 for the length and 5 for the width. The complete Python program is: length = float(input("Enter the rectangle's length: ")) width = float(input("Enter the rectangle's width: ")) area = length * width print(f"The area is {area:.2f} square units.") What line is displayed?
- A
The area is 13.00 square units. - B
The area is 40.00 square units. - C
The area is 40 square units. - D
The area is 85.00 square units.