Free Practice Quiz Question List

5 Functions and Modular Programming Online Quiz Questions

Use this free practice quiz with 20 questions to review 5 Functions and Modular Programming, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What happens when Python executes a function definition such as def greet():?

  1. A

    The body runs as soon as Python reads the def statement.

  2. B

    The body runs when the function is called.

  3. C

    The body runs only when the function is imported.

  4. D

    The body runs only if the function contains a return statement.

02
Choose one
1 point

In def greet_person(name): ... followed by greet_person("Avery"), how should name and "Avery" be classified?

  1. A

    name is an argument and "Avery" is a parameter.

  2. B

    Both name and "Avery" are parameters.

  3. C

    name is a parameter and "Avery" is an argument.

  4. D

    Neither is a parameter or an argument because the function prints instead of returning.

03
Choose one
1 point

What value does log_message("Saved") return when log_message only prints the message and has no return statement?

  1. A

    The empty string

  2. B

    False

  3. C

    The last value printed

  4. D

    None

04
True or false
1 point

True or false: In a Python function call, a positional argument may appear after a keyword argument.

  1. A

    True

  2. B

    False

05
True or false
1 point

True or false: In the example where the module-level variable is status = "ready", assigning status = "busy" inside update_status() changes the module-level variable.

  1. A

    True

  2. B

    False

06
Written response
1 point

What four-letter rule names Python's general search order of local, enclosing, global, and built-in scopes?

07
Written response
1 point

What is the name for a string literal placed as the first statement in a function body to document the function?

08
Fill in the blank
1 point

Complete the statement: To rebind a module-level variable from inside a function, Python provides the statement.

09
Fill in the blank
1 point

Complete the standard entry-point check: if : runs startup code when a file is executed directly but not when it is imported.

10
Choose all
1 point

Which characteristics generally describe well-designed Python functions? Select all correct choices.

  1. A

    One clear responsibility

  2. B

    Explicit inputs and outputs

  3. C

    Limited side effects

  4. D

    Meaningful names

  5. E

    Reliance on hidden global state

11
Choose all
1 point

Which statements about variable-length function parameters are correct? Select all correct choices.

  1. A

    *args collects extra keyword arguments into a dictionary.

  2. B

    *args collects extra positional arguments into a tuple.

  3. C

    **kwargs collects extra positional arguments into a list.

  4. D

    **kwargs collects extra keyword arguments into a dictionary.

12
Open ended
1 point

Design a modular approach for a grade-report program that receives a sequence of scores, calculates an average, assigns a letter grade, and produces a summary. Explain how you would divide the work among functions and why this division improves testing or reuse.

13
Choose one
1 point

What is the difference between square and square(5) when square is a defined Python function?

  1. A

    square always returns the result of squaring zero.

  2. B

    square(5) only stores the function for later use.

  3. C

    square refers to the function object, while square(5) calls it.

  4. D

    square and square(5) are interchangeable expressions.

14
True or false
1 point

True or false: Adding text: str and count: int annotations makes Python automatically enforce those types at runtime.

  1. A

    True

  2. B

    False

15
Choose one
1 point

Consider this definition: def power(base, exponent=2): return base ** exponent. When is the default value 2 for exponent evaluated?

  1. A

    Each time the function is called

  2. B

    The first time the function is called

  3. C

    When the function is defined

  4. D

    Only when the argument is passed by keyword

16
Choose one
1 point

Given def format_score(score, /, *, decimals=2): ..., which call satisfies both the positional-only and keyword-only restrictions?

  1. A

    format_score(score=3.14159, decimals=3)

  2. B

    format_score(3.14159, decimals=3)

  3. C

    format_score(3.14159, 3)

  4. D

    format_score(score=3.14159, 3)

17
Written response
1 point

What four-letter acronym names Python’s general name-resolution order: local, enclosing, global, then built-in?

18
Choose one
1 point

Consider this valid Python function, whose return statement is indented inside the function body: def add_five(value): followed by an indented return value + 5. What is the result of evaluating add_five(10) + 2?

  1. A

    It raises an error because print() cannot be used in a function.

  2. B

    It evaluates to 12 because a displayed value is automatically returned.

  3. C

    It evaluates to 17 because the function returns 15, and then 2 is added.

  4. D

    It evaluates to 15 because the + 2 is ignored.

19
Choose one
1 point

A function is defined as def inspect(*numbers, **options): .... Which statement correctly describes the collected arguments inside the function?

  1. A

    *numbers creates a dictionary, and **options creates a tuple.

  2. B

    Both forms create lists of arguments.

  3. C

    *numbers creates a tuple, and **options creates a dictionary.

  4. D

    Both forms create dictionaries of arguments.

20
Written response
1 point

What numeric value results from evaluating discounted_price(80, 0.25) + 5, where discounted_price(price, discount) returns price * (1 - discount)?