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
Related study packs and tools
02 — Information and Representation
A progressive guide to how computers encode numbers, text, images, and sound as binary data, including the trade-offs and limits of digital representation.
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
05 — Data Structures: Concepts, Operations, and Trade-Offs
A structured guide to the main data structures, their operations, efficiency trade-offs, representations, and practical selection criteria.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
08 — Discrete Mathematics for Computer Science
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
10 — Data, Systems, and Applications
A progression through how data is organized, searched, exposed through software interfaces, and managed through abstraction layers in modern computer systems.
12 — Foundations Capstone
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.