Skip to content

Instantly share code, notes, and snippets.

@64lines
Created December 23, 2013 05:39
Show Gist options
  • Save 64lines/8092170 to your computer and use it in GitHub Desktop.
Save 64lines/8092170 to your computer and use it in GitHub Desktop.
import android
droid = android.Android()
def espacios(num):
spaces = ""
for i in range(0, num):
spaces += " "
return spaces
def calcular_espacios(texto, limite):
resultado = ""
texto = "%s" % texto
if len(texto) == limite:
resultado = texto
elif len(texto) < limite:
espacio = espacios(limite - len(texto))
resultado = texto + espacio
elif len(texto) > limite:
resultado = texto[0:limite]
return resultado
def crear_tabla(limite):
fila_datos = ""
val = 0
una_vez = 0
fila_titulos = ""
for i in range(0, limite):
for j in range(0, limite):
if i == 0:
fila_titulos += calcular_espacios("%s " % (j + 1), 3)
val = val + 1
out = "0%s" % val if val < 10 else val
fila_datos += "%s " % calcular_espacios(out, 3)
fila_titulos += "\n"
if una_vez == 0:
fila_datos = "%s%s" % (fila_titulos, fila_datos)
una_vez = 1
fila_datos += "\n"
print fila_datos
def ejecutar_funciones():
print "Aplicacion de creacion de tablas numericas"
mensaje = "Escribe la longitud"
mensaje += " de la tabla:"
lon = raw_input(mensaje)
try:
lon = int(lon)
except:
pass
crear_tabla(lon)
ejecutar_funciones()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment