# Python hollow figures

2

I just need to know how I could turn these two figures (triangle and rhombus) into hollow figures, that is, only show their edges. my code is this:

``````def Rombo(n):

l = [[' ' for x in range(n)] for z in range(n/2+1)]
for e in range(n):
for i in range(e,n-e):
l[e][i] = '*'
l = l[:0:-1]+l
for i in l:
print ' '.join(i)
#-----------------------------------------------------------------------
def triangulo():
for i in range(5):
for j in range(i+1):
print "4",
print

#---------------------------------------------
def imprimirRombo(n):

n = n//2
for i in range(n,0,-1):
for j in range(n,(n-(i+1)),-1):
print ' ',
for k in range(i+1,n+1):
print '*',
print
for i in range(0,n):
for j in range(n,(n-(i+1)),-1):
print ' ',
for k in range(i+1,n+1):
print '*',
print

#------------------------------------------------------------

for i in range(largo):
if i in[0]:
print("* "*(ancho))
elif i in[(largo-1)]:
print("* "*(ancho))
else:
print("*"+"*"*(ancho)+" *")
#------------------------------------------------------------

for i in range(largo):
if i in[0]:
print("* "*(ancho))
elif i in[(largo-1)]:
print("* "*(ancho))
else:
print("*"+"  "*(ancho)+" *")
#------------------------------------------------------------
for i in range(largo):
if i in[0]:
print(" * "*(ancho+2))
elif i in[(largo-1)]:
print(" * "*(ancho+2))
else:
print(" * "+" 1 "*(ancho)+" * ")

#------------------------------------------------------------
def Opciones():
op=0
while op!=1 and op!=2 and op!=3 and op!=9:
print
print"-----------------------"
print "[1] Rombo"
print "[3] Rombo "
print "[9] terminar la ejecucion"
op = int(raw_input("ingrese opcion: "))
return op

#------------------------------------------------------------
#programa
opcion=Opciones()
while opcion!=9:
if opcion==1:
Rombo(21)
input()
elif opcion==2:
print
print
print
print "|Colores|"
print"-------------------------------------------"
print"Rojo =1 , Amarillo=2, Morado = 3"
print"-------------------------------------------"
print"Seleccione el color y tamaño que desea: "
print"1)Rojo-Grande"
print"2)Amarillo-Grande"
print"4)Rojo-Pequeño"
print"5)Amarillo-Pequeño"
eleccion=int(raw_input("Ingrese su decision: "))
if eleccion ==1:
input()
elif eleccion == 2:
input()
elif eleccion == 3:
input()
elif eleccion == 4:
input()
elif eleccion == 5:
input()
elif eleccion == 6:
input()
else:
print"Debe ingresar un numero valido en el menu"
elif opcion ==3:
imprimirRombo(12)
print
print
print "|Colores|"
print"-------------------------------------------"
print"Rojo =1 , Amarillo=2, Morado = 3"
print"-------------------------------------------"
print"Seleccione el color y tamaño que desea: "
print"1)Rojo-Grande"
print"2)Amarillo-Grande"
print"4)Rojo-Pequeño"
print"5)Amarillo-Pequeño"
decision=int(raw_input("Ingrese su decision: "))
if decision ==1:
imprimirRombo(12)
input()
elif decision ==2:
triangulo()
input()
else:
print"Debe ingresar una opcion valida"
``````

Originally they look like this:

and what I want is something like this:

New: I'm getting in the case of the rhombus but it stays with me ... help: (

`````` def imprimirRombo(n):
espacio = n-1
for x in xrange(1,n):
for y in xrange(1,espacio):
print ' ',
print '*'
for z in xrange(2,2*x-2):
print ' ',
if (x > 1):
print '*'
espacio = espacio -1
espacio=1
for x in xrange(1,n-1):
for y in xrange(1,espacio):
print ' ',
print '*'
for z in xrange(2,2*(n-x)-2):
print ' ',
if (x < n-1):
print '*'
espacio = espacio+1
``````

asked by Wolf 24.12.2018 в 05:18
source

0

I've fixed the triangle and the diamond:

Modify the `triangulo` function like this:

``````def triangulo():
for i in range(5):
for j in range(i+1):
if (j in[0,i] or i == 4):
print "4",
else:
print " ",
print
``````

For the Diamond:

``````def Rombo(n):
l = [[' ' for x in range(n)] for z in range(n/2+1)]
for e in range(n):
for i in range(e,n-e):
if (i in [e, n-e-1]):
l[e][i] = '*'
l = l[:0:-1]+l
for i in l:
print ' '.join(i)
``````