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.
Related study packs and tools
AP Computer Science A: Integrated Java Problem Solving
A practical review of the integrated Java skills, debugging habits, algorithm reasoning, and free-response strategies needed for AP Computer Science A.
Fault Tolerance and Redundant Systems
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
How the Internet Works
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
Java ArrayList and Collections: Operations, Traversals, and Algorithms
Learn how to create, modify, traverse, and analyze Java lists with ArrayList, wrapper types, standard algorithms, and the Collections utility class for AP Computer Science A.
Java Boolean Logic and Selection
Build a clear understanding of Java Boolean expressions, logical operators, selection statements, nested branching, equivalent logic, and systematic code tracing for AP Computer Science A.
Java Foundations and Program Design
A practical introduction to Java program structure, data types, operators, input and output, problem-solving strategy, testing, and debugging for AP Computer Science A.
Java Inheritance and Polymorphism
A practical guide to Java inheritance, constructor chaining, method overriding, polymorphism, access control, and object behavior for tracing and writing AP Computer Science A programs.
Java Objects, Classes, and the String API
A focused guide to Java classes, object references, constructors, methods, strings, wrapper classes, and API usage for AP Computer Science A.
Java Primitive Types and Expression Evaluation
A focused guide to Java primitive types, expression evaluation, numeric conversion, floating-point behavior, integer overflow, and common methods in the Math class for AP Computer Science A.
Java Primitive Types and Expressions
A focused review of Java primitive types, expression evaluation, numeric conversion, arithmetic behavior, Math methods, randomness, and tracing techniques for AP Computer Science A.
Packets, Links, and Network Performance
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
Parallel and Distributed Computing
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.