#!/usr/bin/python
# -*- coding: utf-8 -*-

""" Bosquejo de un programa para convertir de Número a Texto
      Autor: Antonio Carrillo Ledesma
"""


class Convierte:
    # Cadenas para formar los numeros
    unid = [
        "cero",
        "uno",
        "dos",
        "tres",
        "cuatro",
        "cinco",
        "seis",
        "siete",
        "ocho",
        "nueve",
    ]
    edec = ["diez", "once", "doce", "trece", "catorce", "quince"]
    dece = [
        "diez",
        "veinte",
        "treinta",
        "cuarenta",
        "cincuenta",
        "sesenta",
        "setenta",
        "ochenta",
        "noventa",
    ]
    cent = [
        "ciento",
        "doscientos",
        "trescientos",
        "cuatrocientos",
        "quinientos",
        "seiscientos",
        "sietecientos",
        "ochocientos",
        "novecientos",
    ]

    # Convierte de 1 a 999
    def convBas(self, n):
        xc = ""
        xn = n
        if xn > 100 and xn < 1000:
            xc = xc + self.cent[int(xn / 100) - 1]
            xc = xc + " "
            xn = xn - (100 * int(xn / 100))
        if xn == 100:
            xc = xc + "cien"
        if xn > 15 and xn < 100:
            xc = xc + self.dece[int(xn / 10) - 1]
            if (xn % 10) != 0:
                xc = xc + " y "
            xn = xn - (10 * int(xn / 10))
        if xn >= 10 and xn < 16:
            xc = xc + self.edec[xn - 10]
        if xn < 10:
            if xn == 0 and n != 0:
                xc = xc + " "
            else:
                if xn != 0:
                    xc = xc + self.unid[xn]
        return xc

    # Convierte el numero en su expresion escrita
    def conv(self, n):
        xc = ""
        r = 0
        xn = n
        if xn == 1e6:
            xc = xc + "un millon "
            return xc
        if xn >= 2e3 and xn < 1e6:
            r = int(xn / 1e3)
            xc = xc + self.convBas(r)
            xc = xc + " mil "
            xn = int(xn - int(1e3 * r))
        if xn > 1e3 and xn < 2e3:
            if int(xn / 1e3) == 1:
                xc = xc + "un"
            else:
                xc = xc + self.unid[int(xn / 1e3)]
            xc = xc + " mil "
            xn = int(xn - (1e3 * (int(xn / 1e3))))
        if xn == 1e3:
            xc = xc + "un mil "
            return xc
        if xn >= 0 and xn < 1e3:
            xc = xc + self.convBas(xn)
        if xn == 0 and n == 0:
            xc = xc + self.unid[xn]
        return xc


"""
Prueba de las clases
"""
if __name__ == "__main__":
    c = Convierte()
    for i in range(1000001):
        xc = ""
        xc = c.conv(i)
        print(str(i) + " --> " + xc)