Skip to content

Instantly share code, notes, and snippets.

@pablovv72
Created November 26, 2018 22:45
Show Gist options
  • Save pablovv72/f1c4b7746f98e8a815e84ad955b4694c to your computer and use it in GitHub Desktop.
Save pablovv72/f1c4b7746f98e8a815e84ad955b4694c to your computer and use it in GitHub Desktop.
RepartoGastos_1.py
# coding: utf-8
import ui
import clipboard
import console
import speech
def hablar(sender):
speech.say(v['textview1'].text)
def copy(sender):
clipboard.set(v['textview1'].text)
console.hud_alert('Copiado')
def calcular(sender):
comprador = []
importe_total = 0
numero_amigos = int(v['textfield1'].text)
numero_compradores = 0
for i in range(5):
comprador.append(v['textfield{}'.format(str(i + 2))].text)
comprador.append(v['textfield{}'.format(str(i + 7))].text)
if comprador[-2]:
comprador[-1] = float(comprador[-1])
importe_total += comprador[-1]
numero_compradores += 1
else:
comprador.pop()
comprador.pop()
fraccion_importe = importe_total / numero_amigos
resultado = '\nEl importe total son {:.2f} €.\n\n'.format(importe_total)
for i in range(0, numero_compradores * 2, 2):
fraccion_comprador = comprador[i+1] - fraccion_importe
resultado += '{} ha de {} {:.2f} €.\n'.format(
comprador[i], ('pagar' if fraccion_comprador < 0 else 'recibir'),
abs(fraccion_comprador))
resultado += '\nLos demás han de pagar {:.2f} €.'.format(fraccion_importe)
v['textview1'].text = resultado
v = ui.load_view('RepartoGastos_1')
v.bg_color = ('#dadada')
v.present()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment