Functions and Functional Tools Python practice problems
Write reusable functions and meet lambda, map, filter, reduce, closures, generators, and decorators.
Core concepts
Problem-solving patterns
- Define a single responsibility → pass data in → return data out
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #121Reuse a prime-checking function: Prime function true caseIntermediatePremium
Call a reusable function for a prime input.
- #122Reuse a prime-checking function: Prime function false caseIntermediatePremium
Call the same function for a composite input.
- #123Calculate tax with an optional rate: Standard taxIntermediatePremium
Calculate a bill using the standard 18 percent rate.
- #124Calculate tax with an optional rate: Reduced taxIntermediatePremium
Pass a reduced rate explicitly for a special product.
- #125Average any number of values: Four ratingsIntermediatePremium
Average four ratings through a variadic function.
- #126Average any number of values: One readingIntermediatePremium
A variadic function also handles a single supplied value.
- #127Sort records with a lambda: LeaderboardIntermediatePremium
Sort competitors by score, highest first.
- #128Sort records with a lambda: Tie by nameIntermediatePremium
Use the name as a predictable tie breaker.
- #129Square values with map: Positive sequenceIntermediatePremium
Square a short sequence of positive integers.
- #130Square values with map: Signed sequenceIntermediatePremium
Observe that squaring negative and zero values produces nonnegative results.
- #131Filter passing scores: Standard pass markIntermediatePremium
Keep all scores that meet a pass mark of 60.
- #132Filter passing scores: Everyone passesIntermediatePremium
Handle a threshold met by every score.
- #133Multiply values with reduce: Package combinationsIntermediatePremium
Multiply option counts to find the number of package combinations.
- #134Multiply values with reduce: Zero factorIntermediatePremium
Show that any zero factor makes the whole product zero.
- #135Create a discount closure: Festival discountIntermediatePremium
Create and apply a 15 percent festival discount.
- #136Create a discount closure: No discountIntermediatePremium
A closure with zero percent returns the original price.
- #137Generate a countdown: Launch countdownIntermediatePremium
Generate a countdown from five through zero.
- #138Generate a countdown: Immediate finishIntermediatePremium
Starting at zero yields exactly one value.
- #139Log a function call with a decorator: Log a greetingIntermediatePremium
Add a simple audit line whenever the greeting function runs.
- #140Log a function call with a decorator: Forward a spaced argumentIntermediatePremium
The wrapper forwards a full-name argument unchanged.