Last active
September 5, 2023 21:59
-
-
Save kLiHz/2d5d5c4edda74b7971fa6dc484ce174d to your computer and use it in GitHub Desktop.
How much credit is necessary to give customer the cost price?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('items.csv') as f: | |
items = [{ | |
'sales': int(i['sales']), | |
'cost': float(i['cost']), | |
'price': float(i['price']), | |
} for i in csv.DictReader(f, skipinitialspace=True)] | |
tot_sales = sum([i['sales'] for i in items]) | |
rate = sum([(i['price'] / i['cost']) * i['sales'] for i in items]) / tot_sales | |
values = [30, 50, 100] | |
for v in values: | |
print('Store {}, get {:.2f}.'.format(v, v * rate)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sales | cost | price | |
---|---|---|---|
1 | 12.5 | 13 | |
1 | 8 | 10 | |
1 | 7.3 | 9 | |
1 | 9 | 10 | |
1 | 1.5 | 2 | |
1 | 28 | 30 | |
1 | 28.5 | 30 | |
1 | 14.5 | 15 | |
1 | 7 | 10 | |
1 | 190 | 210 | |
1 | 160 | 170 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment