PYTHON
Free Section Starter Challenge
25 min
7. Fruitful Functions, Default Parameters & Scope (LEGB)
Overview: Encapsulate computational logic into pure functions with default arguments and explore scope hierarchy.
Concept & Syntax Guide
Python follows the LEGB scope rule: Local -> Enclosing -> Global -> Built-in. Functions that compute and return values via return are known as fruitful functions. Default parameters allow flexible API contracts.
Hands-On Practice Exercise
Calculate Compound Investment Maturity
Write a function compute_maturity(principal=1000, rate=0.10, years=3) and print the output.
Target Output:
Maturity Amount: ₹1331.0
Need a hint? Click here to reveal
Hint: Check syntax carefully and make sure your code contains:
Maturity Amount: ₹1331.0
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10