summaryrefslogtreecommitdiff
path: root/doc/data/messages/t/too-complex/good.py
blob: 77711f7ec9cd9908ee0f2da357e0fb95c02e4115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
FRUIT_PRICES = {
    "apple": 1.1,
    "pear": 0.8,
    "banana": 1.2,
    "mango": 3.5,
    "peach": 0.5,
    "melon": 4.9,
    "orange": 2.0,
    "strawberry": 2.5,
    "mandarin": 2.3,
    "plum": 0.5,
    "watermelon": 6.4,
}
DISCOUNTED_FRUITS = ["apple", "watermelon"]


def fifty_percent_off(whole):
    return (float(whole)) * 50 / 100


def get_price(fruit):
    full_price = FRUIT_PRICES.get(fruit)
    if fruit in DISCOUNTED_FRUITS:
        return fifty_percent_off(full_price)
    else:
        return full_price


def display_fruit_and_price(fruits):
    for fruit in fruits:
        print(f"{fruit} ${get_price(fruit) :.2f}")


def get_total(fruits):
    return sum(get_price(f) for f in fruits)


fruits_to_buy = ["apple", "orange", "watermelon"]
display_fruit_and_price(fruits_to_buy)
print(f"Total price is ${get_total(fruits_to_buy):.2f}")