Free Practice Quiz Question List

5 Functions and Program Structure Online Quiz Questions

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

20 questions
01
True or false
1 point

True or false: A local variable created inside a Python function normally cannot be used by code outside that function.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Consider this Python code: def greet(customer_name): return "Hello, " + customer_name followed by greet("Maya"). Which statement correctly identifies the parameter and the argument?

  1. A

    "Maya" is the parameter and customer_name is the argument.

  2. B

    customer_name is the parameter and "Maya" is the argument.

  3. C

    Both customer_name and "Maya" are parameters.

  4. D

    Both customer_name and "Maya" are arguments.

03
Written response
1 point

What number is returned by order_total(10, 3, discount=5)?

04
Fill in the blank
1 point

Complete the statement: A variable listed in a function definition is a , while an actual value supplied in a function call is an .

05
Choose one
1 point

What does result contain after this code runs? def double(number): return number * 2 followed by result = double(6).

  1. A

    result stores 12.

  2. B

    result stores the text 12 only because it was printed.

  3. C

    result stores None because multiplication cannot be returned.

  4. D

    The function call causes a syntax error.

06
True or false
1 point

True or false: In Python, a function that reaches its end without executing an explicit return produces None.

  1. A

    True

  2. B

    False

07
Written response
1 point

What modular-design term describes a component whose responsibilities are closely related and focused on one area?

08
Choose all
1 point

Which items are parts of a function's or module's interface? Select all correct choices.

  1. A

    The parameters the component accepts

  2. B

    The values or errors it can produce

  3. C

    Every internal implementation detail

  4. D

    Important side effects, such as changing a file or database

09
Fill in the blank
1 point

Complete the testing sequence: Before calling a function, prepare its inputs during . After execution, compare the actual result with the expected result during .

10
Choose one
1 point

You are testing classify_number, which returns "positive" for values above zero, "negative" for values below zero, and "zero" otherwise. Which input is the most direct boundary case?

  1. A

    8

  2. B

    -3

  3. C

    0

  4. D

    100

11
Choose all
1 point

Which input categories should a programmer consider when designing tests for a function? Select all correct choices.

  1. A

    Typical values

  2. B

    Empty values

  3. C

    Unrelated values

  4. D

    Invalid values

12
Open ended
1 point

A shopping program must read items, calculate a subtotal, apply a discount, calculate tax, and format a receipt. Propose a function decomposition for this program and explain how the decomposition would make testing or debugging easier.

13
Choose one
1 point

Which description best represents the interface of a function?

  1. A

    Only its name and number of lines

  2. B

    Its internal variable names and loop structure

  3. C

    Its name, parameters, possible outputs or errors, and important side effects

  4. D

    Only the data types of its local variables

14
Choose one
1 point

Which part of the rectangle-area example is the function call that executes the function?

  1. A

    The statement def rectangle_area(width, height):

  2. B

    The expression rectangle_area(5, 3)

  3. C

    The statement return width * height

  4. D

    The statement print(area)

15
Choose one
1 point

In the code def rectangle_area(width, height): followed by rectangle_area(5, 3), what is the relationship between width and 5?

  1. A

    Both width and 5 are parameters

  2. B

    width is an argument and 5 is a parameter

  3. C

    width is a parameter and 5 is an argument

  4. D

    Neither width nor 5 is related to the function interface

16
Choose one
1 point

A program needs to read user input, calculate a total, update a file, and print a report. Which design best follows the material's guidance for focused functions?

  1. A

    Put every operation in one function so the program has fewer function calls

  2. B

    Use global variables so all functions can share the same state

  3. C

    Make each function depend on hidden state maintained by other functions

  4. D

    Separate input, calculation, state changes, and reporting into focused functions

17
True or false
1 point

True or false: A good unit test should normally verify a function's observable behavior rather than require a particular internal implementation, such as a specific loop.

  1. A

    True

  2. B

    False

18
Written response
1 point

What design term describes a module whose responsibilities are closely related to one another?

19
Written response
1 point

What testing term describes a later change accidentally breaking behavior that previously worked?

20
Choose one
1 point

Which implementation best reduces hidden dependencies for a tax calculation?

  1. A

    Read the tax rate from a global variable inside apply_tax

  2. B

    Pass price and tax_rate into apply_tax and return the calculated result

  3. C

    Store every price and tax rate in a shared global list

  4. D

    Print the tax result instead of returning it