# Ticket
# Repetición, decisión.
# Se piden importes hasta que se introduzca un cero.
# Junto a cada importe, se calcula el IVA, que puede ser:
#   g - general (21%) r - reducido (10%) s - superreducido (4%)
# Calcular el total de importe y total de IVA
# Descuentos: por el total del importe:
# 0% < 1000 - 5% >= 1000 y < 10000, y 10% >= 10000
# Los descuentos se aplican al importe total y al IVA total.
# Se suman los totales al final.

importe_total = 0
iva_total = 0
importe = -1
iva = ''

while importe != 0:
    importe = float(input("Importe: EUR "))
    if importe > 0:
        importe_total += importe
        iva = input("IVA (g/eneral, r/educido, s/uperreducido): ")
        iva = iva.strip()[0]

        if iva == 'g':
            iva_total += importe * 0.21
        elif iva == 'r':
            iva_total += importe * 0.10
        else:
            iva_total += importe * 0.04

print(str.format("Total antes de impuestos: {0:7.2f}", importe_total))
print(str.format("Total impuestos:          {0:7.2f}", iva_total))

if importe_total < 1000:
    descuento = 0.0
elif importe_total < 10000:
    descuento = 0.05
else:
    descuento = 0.10

print(str.format("Descuento:                 {:3d}%", int(descuento * 100)))

importe_total = importe_total - (importe_total * descuento)
iva_total = iva_total - (iva_total * descuento)

print(str.format("Total antes de impuestos: {0:7.2f}", importe_total))
print(str.format("Total impuestos:          {0:7.2f}", iva_total))
print(str.format("Total:                    {0:7.2f}", importe_total + iva_total))

