-
-
Save abom/db0f8c66782ee91939226b80a6a1397d to your computer and use it in GitHub Desktop.
For bills and stuff
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
#!/usr/bin/env python | |
def calc(gross, delivery, **d): | |
""" | |
usage: | |
>>> calc(120, 9, | |
Ashraf=40, | |
Thabet=20, | |
Awadi=20, | |
Ghanem=20) | |
net: 100 | |
Ghanem: 24.5 | |
Thabet: 24.5 | |
Ashraf: 46.5 | |
Awadi: 24.5 | |
total: 120.0 | |
""" | |
s = sum(map(lambda (x, y): y, d.items())) | |
a2 = [(name, (lambda x:int(x) + [0,0.5,0.5,1][int(4 * (x % 1))])(i * 1.0 * (gross - delivery) / s + 1.0 * delivery / len(d))) for (name, i) in d.items()] | |
print("net: %s"%(s)) | |
print('\n'.join(map(lambda (x, y): '%s: %s'%(x, y), a2))) | |
print('total: %s'%sum(map(lambda (x, y):y, a2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment