diff options
Diffstat (limited to 'tanken.py')
| -rw-r--r-- | tanken.py | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -1,5 +1,6 @@ #!/bin/env python3 + # cost should be given in cents def tanken(drives, cost, service_charge=0): passengers = {} @@ -19,17 +20,19 @@ def tanken(drives, cost, service_charge=0): # collect distances per passenger for p in d[1:]: if p not in passengers: - passengers[p] = {"distance": d[0], - "cost": 0, - "service_charge": 0} + passengers[p] = { + "distance": d[0], + "cost": 0, + "service_charge": 0 + } else: passengers[p]["distance"] += d[0] - + # calculate cost per kilometer if distance <= 0: return None, "Driven distance must be greater than 0!" - c = cost/distance + c = cost / distance for d in drives: # calculate cost per drive split among passengers |
