-
Notifications
You must be signed in to change notification settings - Fork 1
/
jae-example.py
84 lines (61 loc) · 1.87 KB
/
jae-example.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
jä_customer = ["Alice", "Bob"]
jä_products = ["bread", "beer"]
customer = "Bernhard"
products = ["bread", "cerial", "wine"]
free_products = ["cerial"]
def get_normal_price(prod):
if prod == "bread":
return 3
elif prod == "beer":
return 1
else:
return 5
def get_jä_price(prod):
return get_normal_price(prod) * 0.8
def calculate_total_price(products):
total = 0
for product in products:
if customer in jä_customer and product in jä_products:
total = total + get_jä_price(product)
elif not product in free_products:
total = total + get_normal_price(product)
return total
def calculate_total_price(products):
jä_prices = [
get_jä_price(prod)
for prod in products
if prod in jä_products
]
regular_prices = [
get_normal_price(prod)
for prod in products
if prod not in jä_products and product not in free_products
]
return sum(jä_prices) + sum(regular_prices)
total = 0
for prod in products:
if prod not in free_products:
if prod in jä_products:
total = total + get_jä_price(prod)
else:
total = total + get_normal_price(prod)
total = 0
for prod in products:
if prod not in free_products:
if prod in jä_products:
prod_price = get_jä_price(prod)
else:
prod_price = get_normal_price(prod)
total = total + prod_price
total = sum([
(get_jä_price(prod) if prod in jä_products else get_normal_price(prod))
for prod in products
if prod not in free_products
])
total = sum([
get_normal_price(product)
for product in products
if not is_free(product)
])
# AUFGABE: am 1. des monats haben alle rabat, deren name mit B beginnt -> datetime erklären
# TODO: eine funktion, die für user und produktliste die summe gibt