Skip to content

Instantly share code, notes, and snippets.

@badjano
Created Dec 30, 2021
Embed
What would you like to do?
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