Created
May 28, 2019 14:16
-
-
Save eseceve/5eadc381b4820afc10204ab7bcb82518 to your computer and use it in GitHub Desktop.
Poke's script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spends = {} # {'Javi':88490, 'Sebas':69376, 'Andy':63890, 'Fabian':57320} | |
pays = {} | |
gets = {} | |
def split(spends): | |
total = sum(spends.values()) | |
integrants = len(spends.keys()) | |
divided = total/integrants | |
print('Gastos: {}'.format(spends)) | |
print('Se gasto en total: {}'.format(total)) | |
print('Dividido entre {}: {} cada uno'.format(integrants, divided)) | |
for key, amount in spends.items(): | |
if amount < divided: | |
must_pay(key, divided - amount) | |
if amount > divided: | |
must_get(key, amount - divided) | |
for p_key, p_amount in pays.items(): | |
for g_key, g_amount in gets.items(): | |
if (p_amount == 0) or (g_amount == 0): | |
continue | |
if p_amount < g_amount: | |
print('{} Paga {} a {}'.format(p_key, p_amount, g_key)) | |
pays.pop(p_key) | |
p_amount = 0 | |
if p_amount > g_amount: | |
print('{} Paga {} a {}'.format(p_key, g_amount, g_key)) | |
gets[g_key] -= g_amount | |
p_amount -= g_amount | |
def must_pay(guy, amount): | |
pays[guy] = amount | |
def must_get(guy, amount): | |
gets[guy] = amount | |
split(spends) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment