

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Pure Functions
incomplete
2: Pure Function Review
incomplete
3: Reference vs. Value
incomplete
4: Pass by Reference Impurity
incomplete
5: Input and Output
incomplete
6: Should I I/O?
incomplete
7: No-Op
incomplete
8: Memoization
incomplete
9: Referential Transparency
incomplete
10: Pure Functions Practice
incomplete
11: Pure Functions Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Pure functions have a lot of benefits. Whenever possible, good developers try to use pure functions instead of impure functions. Remember, pure functions:
These properties make pure functions easier to test, debug, and think about.
Refer to the following examples to answer the questions.
def multiply_by2(nums: list[int]) -> list[int]:
products: list[int] = []
for num in nums:
products.append(num * 2)
return products
balance: int = 1000
cars: list[str] = []
def buy_car(new_car: str) -> None:
global balance
cars.append(new_car)
balance -= 69
import random
def roll_die(num_sides: int) -> int:
return random.randint(1, num_sides)