True or false: A local variable created inside a Python function normally cannot be used by code outside that function.
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.
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?
- A
"Maya"is the parameter andcustomer_nameis the argument. - B
customer_nameis the parameter and"Maya"is the argument. - C
Both
customer_nameand"Maya"are parameters. - D
Both
customer_nameand"Maya"are arguments.
What number is returned by order_total(10, 3, discount=5)?
Complete the statement: A variable listed in a function definition is a , while an actual value supplied in a function call is an .
What does result contain after this code runs? def double(number): return number * 2 followed by result = double(6).
- A
resultstores 12. - B
resultstores the text12only because it was printed. - C
resultstoresNonebecause multiplication cannot be returned. - D
The function call causes a syntax error.
True or false: In Python, a function that reaches its end without executing an explicit return produces None.
- A
True
- B
False
What modular-design term describes a component whose responsibilities are closely related and focused on one area?
Which items are parts of a function's or module's interface? Select all correct choices.
- A
The parameters the component accepts
- B
The values or errors it can produce
- C
Every internal implementation detail
- D
Important side effects, such as changing a file or database
Complete the testing sequence: Before calling a function, prepare its inputs during . After execution, compare the actual result with the expected result during .
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?
- A
8
- B
-3
- C
0
- D
100
Which input categories should a programmer consider when designing tests for a function? Select all correct choices.
- A
Typical values
- B
Empty values
- C
Unrelated values
- D
Invalid values
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.
Which description best represents the interface of a function?
- A
Only its name and number of lines
- B
Its internal variable names and loop structure
- C
Its name, parameters, possible outputs or errors, and important side effects
- D
Only the data types of its local variables
Which part of the rectangle-area example is the function call that executes the function?
- A
The statement def rectangle_area(width, height):
- B
The expression rectangle_area(5, 3)
- C
The statement return width * height
- D
The statement print(area)
In the code def rectangle_area(width, height): followed by rectangle_area(5, 3), what is the relationship between width and 5?
- A
Both width and 5 are parameters
- B
width is an argument and 5 is a parameter
- C
width is a parameter and 5 is an argument
- D
Neither width nor 5 is related to the function interface
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?
- A
Put every operation in one function so the program has fewer function calls
- B
Use global variables so all functions can share the same state
- C
Make each function depend on hidden state maintained by other functions
- D
Separate input, calculation, state changes, and reporting into focused functions
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.
- A
True
- B
False
What design term describes a module whose responsibilities are closely related to one another?
What testing term describes a later change accidentally breaking behavior that previously worked?
Which implementation best reduces hidden dependencies for a tax calculation?
- A
Read the tax rate from a global variable inside apply_tax
- B
Pass price and tax_rate into apply_tax and return the calculated result
- C
Store every price and tax rate in a shared global list
- D
Print the tax result instead of returning it