Skip to content

Commit 85af62e

Browse files
committed
Improving map examples
1 parent 75421ce commit 85af62e

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

python_utils/map/example_1.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1+
""" Applying TAX """
12
prices = [1.09, 23.56, 57.84, 4.56, 6.78]
2-
TAX_RATE = .08
3+
TAX_RATE = 8
34

45

5-
def get_price_with_tax(price):
6-
return price * (1 + TAX_RATE)
6+
def get_price_with_tax(prices, tax):
7+
return map(lambda p: p * (1 + tax / 100), prices)
78

89

9-
final_prices = map(get_price_with_tax, prices)
10+
final_prices = get_price_with_tax(prices, TAX_RATE)
1011
final_prices = list(final_prices)
11-
print(final_prices)
12+
print("Applying TAX")
13+
print(f"\tPrices: {prices}")
14+
print(f"\tPrices with tax ({TAX_RATE}%): {final_prices}\n")
15+
16+
""" Applying DISCOUNT """
17+
prices = [100, 200, 300, 400, 500]
18+
DISCOUNT_RATE = 15
19+
20+
21+
def get_price_with_discount(prices, discount):
22+
return map(lambda p: p * (1 - discount / 100), prices)
23+
24+
25+
final_prices = get_price_with_discount(prices, DISCOUNT_RATE)
26+
final_prices = list(final_prices)
27+
print("Applying DISCOUNT")
28+
print(f"\tPrices: {prices}")
29+
print(f"\tPrices with discount ({DISCOUNT_RATE}%): {final_prices}\n")

0 commit comments

Comments
 (0)