Functions and Program Design Python practice problems
Parameters, return values, default and keyword arguments, scope, decomposition, and reusable code.
Core concepts
Problem-solving patterns
- function · return
- default argument · function
- args · unpacking
- closure · scope
- generator · yield
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 12 problems in this topic
Work from top to bottom to build the concept gradually.
- #061Reuse a prime-checking function: Prime function true caseStarterPremium
Call a reusable function for a prime input.
- #062Reuse a prime-checking function: Prime function false caseStarterPremium
Call the same function for a composite input.
- #063Calculate tax with an optional rate: Standard taxStarterPremium
Calculate a bill using the standard 18 percent rate.
- #064Calculate tax with an optional rate: Reduced taxStarterPremium
Pass a reduced rate explicitly for a special product.
- #065Average any number of values: Four ratingsBeginnerPremium
Average four ratings through a variadic function.
- #066Average any number of values: One readingBeginnerPremium
A variadic function also handles a single supplied value.
- #067Create a discount closure: Festival discountBeginnerPremium
Create and apply a 15 percent festival discount.
- #068Create a discount closure: No discountBeginnerPremium
A closure with zero percent returns the original price.
- #069Generate a countdown: Launch countdownBeginnerPremium
Generate a countdown from five through zero.
- #070Generate a countdown: Immediate finishBeginnerPremium
Starting at zero yields exactly one value.
- #071Log a function call with a decorator: Log a greetingBeginnerPremium
Add a simple audit line whenever the greeting function runs.
- #072Log a function call with a decorator: Forward a spaced argumentIntermediatePremium
The wrapper forwards a full-name argument unchanged.