Created
June 6, 2017 15:25
-
-
Save lizy14/735412be637c0388f94684854af3349f to your computer and use it in GitHub Desktop.
外卖AA计算器
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
# 外卖AA计算器,为处理外送费、满减 | |
# 输入总价、各人比例 | |
# eg. python3 aa.py 44+71 13+18 19+28 13+18 13+18 | |
import sys | |
def aa(total, per_person): | |
sum_per_person = sum(per_person) | |
return [p * total / sum_per_person for p in per_person] | |
def trunc(x): | |
return "{0:.2f}".format(round(x, 2)) | |
total = sys.argv[1] | |
per_person = sys.argv[2:] | |
total = eval(total) | |
per_person = [eval(p) for p in per_person] | |
result = aa(total, per_person) | |
print([trunc(i) for i in result]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment