What happens when Python executes a function definition such as def greet():?
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.
In def greet_person(name): ... followed by greet_person("Avery"), how should name and "Avery" be classified?
- A
nameis an argument and"Avery"is a parameter. - B
Both
nameand"Avery"are parameters. - C
nameis a parameter and"Avery"is an argument. - D
Neither is a parameter or an argument because the function prints instead of returning.
What value does log_message("Saved") return when log_message only prints the message and has no return statement?
- A
The empty string
- B
False - C
The last value printed
- D
None
True or false: In a Python function call, a positional argument may appear after a keyword argument.
- A
True
- B
False
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.
- A
True
- B
False
What four-letter rule names Python's general search order of local, enclosing, global, and built-in scopes?
What is the name for a string literal placed as the first statement in a function body to document the function?
Complete the statement: To rebind a module-level variable from inside a function, Python provides the statement.
Complete the standard entry-point check: if : runs startup code when a file is executed directly but not when it is imported.
Which characteristics generally describe well-designed Python functions? Select all correct choices.
- A
One clear responsibility
- B
Explicit inputs and outputs
- C
Limited side effects
- D
Meaningful names
- E
Reliance on hidden global state
Which statements about variable-length function parameters are correct? Select all correct choices.
- A
*argscollects extra keyword arguments into a dictionary. - B
*argscollects extra positional arguments into a tuple. - C
**kwargscollects extra positional arguments into a list. - D
**kwargscollects extra keyword arguments into a dictionary.
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.
What is the difference between square and square(5) when square is a defined Python function?
- A
squarealways returns the result of squaring zero. - B
square(5)only stores the function for later use. - C
squarerefers to the function object, whilesquare(5)calls it. - D
squareandsquare(5)are interchangeable expressions.
True or false: Adding text: str and count: int annotations makes Python automatically enforce those types at runtime.
- A
True
- B
False
Consider this definition: def power(base, exponent=2): return base ** exponent. When is the default value 2 for exponent evaluated?
- A
Each time the function is called
- B
The first time the function is called
- C
When the function is defined
- D
Only when the argument is passed by keyword
Given def format_score(score, /, *, decimals=2): ..., which call satisfies both the positional-only and keyword-only restrictions?
- A
format_score(score=3.14159, decimals=3) - B
format_score(3.14159, decimals=3) - C
format_score(3.14159, 3) - D
format_score(score=3.14159, 3)
What four-letter acronym names Python’s general name-resolution order: local, enclosing, global, then built-in?
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?
- A
It raises an error because
print()cannot be used in a function. - B
It evaluates to 12 because a displayed value is automatically returned.
- C
It evaluates to 17 because the function returns 15, and then 2 is added.
- D
It evaluates to 15 because the
+ 2is ignored.
A function is defined as def inspect(*numbers, **options): .... Which statement correctly describes the collected arguments inside the function?
- A
*numberscreates a dictionary, and**optionscreates a tuple. - B
Both forms create lists of arguments.
- C
*numberscreates a tuple, and**optionscreates a dictionary. - D
Both forms create dictionaries of arguments.
What numeric value results from evaluating discounted_price(80, 0.25) + 5, where discounted_price(price, discount) returns price * (1 - discount)?
Related study packs and tools
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.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
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.
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.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.