1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| # ==============================================================================
# LITTERAL
# ==============================================================================
"""LITTERAL : ecris un nombre"""
__author__ = "Ph"
__version__ = "1.0"
__date__ = "26/10/2008"
__usage__ = """
Input : entrez un nombre
Note : enter empty line to stop interaction loop"""
# ------------------------------------------------------------------------------
def affich19(nb):
if nb==1:
print("un ")
if nb==2:
print("deux ")
if nb==3:
print("trois ")
if nb==4:
print("quatre ")
if nb==5:
print("cinq ")
if nb==6:
print("six ")
if nb==7:
print("sept ")
if nb==8:
print("huit ")
if nb==9:
print("neuf ")
if nb==10:
print("dix ")
if nb==11:
print("onze ")
if nb==12:
print("douze ")
if nb==13:
print("treize ")
if nb==14:
print("quatorze ")
if nb==15:
print("quinze ")
if nb==16:
print("seize ")
if nb==17:
print("dix - sept ")
if nb==18:
print("dix - huit ")
if nb==19:
print("dix - neuf ")
# ------------------------------------------------------------------------------
def affich99(diz,unit):
#------------------------------------------------
if diz==2:
print("vingt ")
if diz==3:
print("trente ")
if diz==4:
print("quarante ")
if diz==5:
print("cinquante ")
if diz==6:
print("soixante ")
if diz==8:
print("quatre - vingt")
if diz==9:
print("quatre - vingt")
#------------------------------------------------
if (diz==2 or diz==3 or diz==4 or diz==5 or diz==6):
if (unit==1):
print("et ")
else:
print("- ")
if (diz==8):
if (not unit):
print("s ")
else:
print(" - ")
if (diz==7 or diz==9):
if (diz==7 and unit == 1):
print(" et ")
else:
print(" - ")
#-------------------------------------------------
if (diz==1 or diz==7 or diz==9) :
affich19(10+unit)
else:
affiche19(unit)
# ------------------------------------------------------------------------------
def affich999(cent, diz, unit):
if (cent):
if (cent>1):
affich19(cent)
if (cent==1 or unit or diz):
print("cent ")
else:
print("cents ")
affiche99(diz, unit);
# ------------------------------------------------------------------------------
def affich_nb(nb):
tab=[0,0,0,0,0,0,0,0,0,0,0,0]
aux=0
aux1=0
aux2=0
aux3=0
if (not nb):
print("zero")
else:
for i in range(11): #0-9
tab[i]=(nb%10),
nb=nb//10
for i in range(9,-1,-3):#9 puis 6 puis 3 puis 0
aux=tab[i+2]*100+tab[i+1]*10+tab[i]
if (aux):
if (i!=3 or aux !=1):
affich999(tab[i+2],tab[i+1],tab[i])
if (i==3):
print("mille")
break
if (i==6):
print("million")
break
if (i==9):
print("milliard")
break
if (aux!=1 and (i==6 or i==9)):
print("s")
print(" ")
# ------------------------------------------------------------------------------
def main():
"""main program of the litteral module"""
while True:
line = raw_input("<> Entrez un nombre : ")
if line == '':break
try:
affich_nb(int(line))
except ValueError:
print "Error : invalid input value"
# ------------------------------------------------------------------------------
if __name__ == "__main__":
print "%s\n%s%s\n%s" % ('='*80, __doc__, __usage__, '='*80)
main()
# ============================================================================== |
Partager