Free Practice Quiz Question List

1 Python Syntax and Program Structure Online Quiz Questions

Use this free practice quiz with 20 questions to review 1 Python Syntax and Program Structure, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What determines which statements belong to the body of an if, for, while, or function definition in Python?

  1. A

    Indentation groups statements into blocks.

  2. B

    Curly braces group statements into blocks.

  3. C

    Semicolons group statements into blocks.

  4. D

    Quotation marks group statements into blocks.

02
True or false
1 point

True or false: If a user types 27 in response to input(), the returned value is still a string.

  1. A

    True

  2. B

    False

03
Fill in the blank
1 point

Complete the sentence: When an indented Python block is syntactically required but no action is needed yet, use .

04
Choose one
1 point

What value does this Python expression produce? (2 + 3) * 4

  1. A

    14

  2. B

    20

  3. C

    24

  4. D

    26

05
Choose all
1 point

Select all expressions that convert user-entered text to an integer.

  1. A

    int(age_text)

  2. B

    age_text + 1

  3. C

    str(age_text)

  4. D

    int(input("Age: "))

06
Written response
1 point

What exception does Python normally raise when a program uses a name before assigning a value to it?

07
Fill in the blank
1 point

Complete the sentence: In Python, a one-line comment begins with and continues to the end of the physical line.

08
True or false
1 point

True or false: In Python, is is the recommended operator for comparing ordinary values such as two integers.

  1. A

    True

  2. B

    False

09
Choose one
1 point

What does this statement write, including its ending character? print("A", "B", sep="-", end="!")

  1. A

    A B

  2. B

    A-B followed by a newline

  3. C

    A-B!

  4. D

    A!B!

10
Choose all
1 point

Select all strings that can be used as ordinary Python names.

  1. A

    student_count

  2. B

    2nd_place

  3. C

    maximum-speed

  4. D

    Total

  5. E

    for

11
Written response
1 point

What integer value does the Python expression 7 // 2 produce?

12
Open ended
1 point

A program contains the statement print("Area:", area and reports a syntax error. Explain the cause of the error and write the corrected statement.

13
Choose one
1 point

A long arithmetic expression should be split across physical lines while remaining one logical line. Which approach is generally clearest in Python?

  1. A

    End each physical line with a semicolon.

  2. B

    Enclose the expression in parentheses.

  3. C

    Indent the second physical line with a tab.

  4. D

    Put a comment at the end of the first physical line.

14
Choose one
1 point

Which statement correctly distinguishes Python’s is and == operators?

  1. A

    is converts both values to strings before comparing them.

  2. B

    is performs numeric comparison, while == performs text comparison.

  3. C

    is checks whether a value is truthy, while == checks whether it is false.

  4. D

    is tests object identity, while == tests value equality.

15
True or false
1 point

In label = "Chapter #1", the # character begins a Python comment.

  1. A

    True

  2. B

    False

16
Written response
1 point

Which built-in Python function reads one line of user input and returns it as a string?

17
Choose one
1 point

What happens in Python when total, Total, and TOTAL are used as names?

  1. A

    total and Total refer to the same name, but TOTAL is different.

  2. B

    total, Total, and TOTAL are three different names.

  3. C

    Only TOTAL is a valid Python name.

  4. D

    Python treats all three names as invalid because they differ only by case.

18
Choose one
1 point

After width, height = 8, 5 and area = width * height execute, what value is printed by print(area)?

  1. A

    13

  2. B

    40

  3. C

    85

  4. D

    3

19
Choose one
1 point

What is the value of can_enter after this code executes: colors = ["red", "blue", "green"]; requested = "blue"; is_available = requested in colors; is_guest = False; can_enter = is_available or is_guest?

  1. A

    True

  2. B

    False

  3. C

    blue

  4. D

    None

20
Written response
1 point

What integer value is assigned to result by base = 3; exponent = 2; result = base ** exponent?