Skip to content

Instantly share code, notes, and snippets.

@badjano
Created December 30, 2021 22:23
Show Gist options
  • Save badjano/42d40d61cb38d05bbeb793e182b76526 to your computer and use it in GitHub Desktop.
Save badjano/42d40d61cb38d05bbeb793e182b76526 to your computer and use it in GitHub Desktop.
Script de rateio de gastos em python
names = ["Fulano", "Sicrano", "Beltrano"]
costs = [397.03, 199.42, 0]
individual_cost = sum(costs) / len(costs)
costs_str = "\n".join([f"{a} gastou R${b}" for a, b in zip(names, costs)])
print(f"Sabendo que:\n{costs_str}\n")
print(f"E que o custo total foi R${sum(costs):.02f}\ne o individual foi R${individual_cost:.02f}\n")
for n, c in zip(names, costs):
specific_cost = individual_cost - c
word = "receber" if specific_cost < 0 else "pagar"
print(f"{n} deve {word}: R${abs(specific_cost):.02f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment