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

How does Python normally delimit the block of statements controlled by a compound-statement header such as an if statement?

  1. A

    A pair of braces

  2. B

    Indentation after a colon

  3. C

    A semicolon at the end of the header

  4. D

    A comma after the condition

02
Choose one
1 point

Which token starts a Python comment when it appears outside a string literal?

  1. A

    //

  2. B

    /*

  3. C

    #

  4. D

    --

03
Choose one
1 point

Which statement correctly reads a quantity that will be used as an integer in later arithmetic?

  1. A

    quantity = int(input("Quantity: "))

  2. B

    quantity = input("Quantity: ")

  3. C

    quantity = str(input("Quantity: "))

  4. D

    quantity = print(input("Quantity: "))

04
Choose all
1 point

Which grouping characters allow a Python statement to continue across multiple physical lines? Select all correct answers.

  1. A

    Parentheses

  2. B

    Brackets

  3. C

    Braces

  4. D

    Semicolons

  5. E

    Colons

05
Choose all
1 point

Which two statements accurately describe Python’s Boolean operators? Select all correct answers.

  1. A

    and is true when both operands are true.

  2. B

    or is true when at least one operand is true.

  3. C

    not is true only when both operands are true.

  4. D

    and always returns the Boolean object True or False.

06
True or false
1 point

True or false: In a module containing if __name__ == "__main__": main(), the call to main() normally runs when another module imports it.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: Python treats count and Count as different names.

  1. A

    True

  2. B

    False

08
Written response
1 point

When a Python file is executed directly as a script, what exact string value does its special variable __name__ have?

09
Written response
1 point

What value does the Python expression 7 / 2 produce?

10
Fill in the blank
1 point

A string literal placed as the first statement in a module, function, or class is called a .

11
Fill in the blank
1 point

In Python, a compound-statement header such as an if header ends with a before its indented suite.

12
Open ended
1 point

Explain how name = supplied_name or "Guest" works for both truthy and falsy values of supplied_name. Include what short-circuit evaluation contributes and whether the result must be a Boolean.

13
Choose one
1 point

What is the main purpose of placing main() inside if __name__ == "__main__":?

  1. A

    It prevents all top-level statements from executing.

  2. B

    It runs main() when the file is executed directly but not when imported.

  3. C

    It makes every function execute immediately when the module loads.

  4. D

    It converts the module into a package.

14
True or false
1 point

True or false: A comment beginning with # is ignored by Python during parsing when the # appears outside a string literal.

  1. A

    True

  2. B

    False

15
Written response
1 point

What is the name of Python's // operator?

16
Written response
1 point

In the pattern if __name__ == "__main__":, what special variable is being tested?

17
Choose one
1 point

A program needs to add 3 to a whole-number quantity entered by the user. Which expression obtains that quantity as an integer?

  1. A

    int(input("Quantity: "))

  2. B

    input("Quantity: ")

  3. C

    str(input("Quantity: "))

  4. D

    float(input("Quantity: "))

18
Choose one
1 point

Which punctuation mark must be added to make this Python structure syntactically complete?

if score > 90
print("Excellent")

  1. A

    A semicolon

  2. B

    A comma

  3. C

    A colon

  4. D

    A period

19
Choose one
1 point

Which result is correct for this Python code?

if logged_in:
print("Welcome")
print("Dashboard")

  1. A

    The statements use inconsistent indentation within the if suite, producing an IndentationError.

  2. B

    The statements are at the same indentation level as the if header, which is required for the suite.

  3. C

    The statements are separated with semicolons, which makes the block invalid.

  4. D

    The if header does not end with a colon, so Python cannot begin the suite.

20
Choose one
1 point

A Python file defines a main() function and ends with if __name__ == "__main__": followed by main(). What happens when another module imports this file?

  1. A

    The guard prevents main() from running during import.

  2. B

    The guard converts the module into a class.

  3. C

    The guard makes every top-level statement execute twice.

  4. D

    The guard prevents the module from being imported.