Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

A Python program contains age = input("Age: "). What is required before the program can safely evaluate age + 1 as numerical addition?

  1. A

    It returns an integer automatically when digits are entered.

  2. B

    It returns a string, so numerical input usually needs conversion.

  3. C

    It returns a Boolean value indicating whether the input is valid.

  4. D

    It returns a floating-point number automatically.

02
Choose all
1 point

Select all the valid Python identifiers from the following choices.

  1. A

    first_name

  2. B

    2nd_place

  3. C

    _count2

  4. D

    return

03
True or false
1 point

True or false: In Python, the statement score = 100 tests whether score is equal to 100.

  1. A

    True

  2. B

    False

04
Written response
1 point

What Python type name is produced by evaluating type(float("3.5")).__name__?

05
Fill in the blank
1 point

A is a named reference to a value that a program can store and use later.

06
True or false
1 point

True or false: Python uses uppercase naming as a convention for constants, but it still technically allows the name to be reassigned.

  1. A

    True

  2. B

    False

07
Choose one
1 point

If x is initially 4, what is the value of x after Python executes x = x + 1?

  1. A

    It compares x with x + 1.

  2. B

    It creates a new variable named x + 1.

  3. C

    It increases the current value of x by 1 and stores the result in x.

  4. D

    It causes an error because a variable cannot appear on both sides.

08
Choose all
1 point

Select all the expressions that perform a successful explicit type conversion based on the material.

  1. A

    int("42")

  2. B

    str(2026)

  3. C

    int("hello")

  4. D

    input("Enter a number: ")

09
Written response
1 point

Enter the integer result of evaluating int(-7.9) in Python.

10
Fill in the blank
1 point

In the input–process–output pattern, the program first receives data as and later reports the result as .

11
Choose one
1 point

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?

  1. A

    The area is 40 square units.

  2. B

    The area is 40.0 square units.

  3. C

    The area is 40.000 square units.

  4. D

    The area is 40.00 square units.

12
Open ended
1 point

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.

13
Choose one
1 point

Which revision correctly allows a program to read a user's age and print the age one year later?

  1. A

    age = input("Age: ") followed by print(age + 1)

  2. B

    age = int(input("Age: ")) followed by print(age + 1)

  3. C

    age = str(input("Age: ")) followed by print(age + 1)

  4. D

    age = bool(input("Age: ")) followed by print(age + 1)

14
Choose one
1 point

After this Python code runs, what value does score have?

score = 80

score = 95

  1. A

    80

  2. B

    95

  3. C

    175

  4. D

    An error occurs because score cannot be reassigned

15
Choose one
1 point

Which of the following is a valid Python identifier?

  1. A

    2student_name

  2. B

    class

  3. C

    student_name

  4. D

    student-name

16
Choose one
1 point

What are the values of x and y after this Python code runs?

x, y = 10, 20

x, y = y, x

  1. A

    x = 10, y = 20

  2. B

    x = 20, y = 10

  3. C

    x = 10, y = 10

  4. D

    The statement produces a syntax error

17
True or false
1 point

True or false: In Python, writing a constant name in uppercase prevents the program from reassigning that value.

  1. A

    True

  2. B

    False

18
Written response
1 point

What integer does Python return for int(-7.9)?

19
Written response
1 point

What Python function reads a line from the user and returns the entered data as a string?

20
Choose one
1 point

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?

  1. A

    The area is 13.00 square units.

  2. B

    The area is 40.00 square units.

  3. C

    The area is 40 square units.

  4. D

    The area is 85.00 square units.