download: alfabeto_calc.py
#!/usr/bin/env python
# algunas definiciones
num = {'B':8, 'E':3, 'G':9, 'h':4, 'I':1, 'L':7, 'O':0, 'S':5, 'Z':2}
def upper_except_h(p):
r = ''
for l in p:
if l <> 'h':
r += l.upper()
else:
r += 'h'
return r
def numerar(p):
p = upper_except_h(p)
r = ''
for l in p:
r += str(num[l])
r = r[::-1] # invierte el string
if r[0] == "0": # si comienza con un cero...
r = "0." + r[1:] # cambiarlo por un cero punto.
return r
# a trabajar
file = open("palabras.txt","r")
palabras = [p[:-1] for p in file.readlines()]
for p in palabras:
u = upper_except_h(p)
n = numerar(u)
print "%s = %s = %s" % (p,u,n)
# Ver: http://en.wikipedia.org/wiki/List_of_calculator_words#Notes