pyPython Practice LabFrom first print to final round
TOPIC 07 OF 18

Functions and Functional Tools Python practice problems

Write reusable functions and meet lambda, map, filter, reduce, closures, generators, and decorators.

20 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Reuse a prime-checking functionCalculate tax with an optional rateAverage any number of valuesSort records with a lambdaSquare values with mapFilter passing scoresMultiply values with reduceCreate a discount closure
REUSABLE THINKING

Problem-solving patterns

  • Define a single responsibility → pass data in → return data out
INTERVIEW SIGNALS

Reported company tags

TCSInfosysAccenture
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #121
    Reuse a prime-checking function: Prime function true case

    Call a reusable function for a prime input.

    IntermediatePremium
  2. #122
    Reuse a prime-checking function: Prime function false case

    Call the same function for a composite input.

    IntermediatePremium
  3. #123
    Calculate tax with an optional rate: Standard tax

    Calculate a bill using the standard 18 percent rate.

    IntermediatePremium
  4. #124
    Calculate tax with an optional rate: Reduced tax

    Pass a reduced rate explicitly for a special product.

    IntermediatePremium
  5. #125
    Average any number of values: Four ratings

    Average four ratings through a variadic function.

    IntermediatePremium
  6. #126
    Average any number of values: One reading

    A variadic function also handles a single supplied value.

    IntermediatePremium
  7. #127
    Sort records with a lambda: Leaderboard

    Sort competitors by score, highest first.

    IntermediatePremium
  8. #128
    Sort records with a lambda: Tie by name

    Use the name as a predictable tie breaker.

    IntermediatePremium
  9. #129
    Square values with map: Positive sequence

    Square a short sequence of positive integers.

    IntermediatePremium
  10. #130
    Square values with map: Signed sequence

    Observe that squaring negative and zero values produces nonnegative results.

    IntermediatePremium
  11. #131
    Filter passing scores: Standard pass mark

    Keep all scores that meet a pass mark of 60.

    IntermediatePremium
  12. #132
    Filter passing scores: Everyone passes

    Handle a threshold met by every score.

    IntermediatePremium
  13. #133
    Multiply values with reduce: Package combinations

    Multiply option counts to find the number of package combinations.

    IntermediatePremium
  14. #134
    Multiply values with reduce: Zero factor

    Show that any zero factor makes the whole product zero.

    IntermediatePremium
  15. #135
    Create a discount closure: Festival discount

    Create and apply a 15 percent festival discount.

    IntermediatePremium
  16. #136
    Create a discount closure: No discount

    A closure with zero percent returns the original price.

    IntermediatePremium
  17. #137
    Generate a countdown: Launch countdown

    Generate a countdown from five through zero.

    IntermediatePremium
  18. #138
    Generate a countdown: Immediate finish

    Starting at zero yields exactly one value.

    IntermediatePremium
  19. #139
    Log a function call with a decorator: Log a greeting

    Add a simple audit line whenever the greeting function runs.

    IntermediatePremium
  20. #140
    Log a function call with a decorator: Forward a spaced argument

    The wrapper forwards a full-name argument unchanged.

    IntermediatePremium