Skip to content

Instantly share code, notes, and snippets.

@xleon
Last active December 31, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xleon/868adf9bd38fced154f7c5afb52d26ef to your computer and use it in GitHub Desktop.
Save xleon/868adf9bd38fced154f7c5afb52d26ef to your computer and use it in GitHub Desktop.
"""
Ejemplo simple de calculadora para IVA e IRPF dada una base imponible
"""
from colorama import init, Fore, Back, Style
init()
IVA_PERCENT = 0.21
IRPF_PERCENT = 0.15
CURRENCY = '€'
def run():
separator = '----------------------------'
print('\nCalculadora de IVA / IRPF')
def format_number(number):
return '{0:,.2f}'.format(number)
while True:
print(separator + Fore.CYAN)
subtotal_str = input('Escribe base imponible (decimales con punto): ')
try:
subtotal = float(subtotal_str) if '.' in subtotal_str else int(subtotal_str)
iva = subtotal * IVA_PERCENT
irpf = subtotal * IRPF_PERCENT
total = subtotal + iva - irpf
revenue = subtotal - irpf
print(Fore.WHITE + separator)
print('Subtotal:', format_number(subtotal), CURRENCY)
print('IVA:', format_number(iva), CURRENCY)
print('IRPF: -' + Fore.RED + format_number(irpf) + Fore.WHITE, CURRENCY)
print('Total:', Fore.CYAN + format_number(total) + Fore.WHITE, CURRENCY)
print('Neto:', Fore.GREEN + format_number(revenue) + Fore.WHITE, CURRENCY)
print(' ')
except ValueError:
print('formato de cantidad no válido')
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment