Skip to content

Instantly share code, notes, and snippets.

@lizy14
Created June 6, 2017 15:25
Show Gist options
  • Save lizy14/735412be637c0388f94684854af3349f to your computer and use it in GitHub Desktop.
Save lizy14/735412be637c0388f94684854af3349f to your computer and use it in GitHub Desktop.
外卖AA计算器
# 外卖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