Datasets:
File size: 680 Bytes
93237a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from fractions import Fraction
gross_cents = 3 * 1250 + 2 * 800
goods_cents = gross_cents * 9 // 10
assert gross_cents * 9 % 10 == 0
shipping_cents = 500 if goods_cents < 5000 else 0
raw_tax_cents = Fraction(goods_cents * 8, 100)
rounded = raw_tax_cents + Fraction(1, 2)
tax_cents = rounded.numerator // rounded.denominator
def money(cents):
return f"{cents // 100}.{cents % 100:02d}"
result = {"gross": money(gross_cents), "discounted_goods": money(goods_cents),
"shipping": money(shipping_cents), "tax": money(tax_cents),
"total": money(goods_cents + shipping_cents + tax_cents)}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|