Sep-06-2019, 08:41 PM
Hello, I'm new to Python and i had a class assignment that was to draw figures as contours of a regular hexagon and of rectangles and isosceles triangles. I was able to make the necessary patterns (and gave a hard job to me hahahaha :/), but I forgot that I could not leave blanks to the right of the figure, i.e each line must end as soon as the last character is printed on this line, and couldn't think of a way to do it, could someone give me a light on it? I thought of using concatenated strings or something to limit the print on each row, but i couldn't develop it :/
This is the code for the hollow hexagon in function of variable "ladoqh" that is the side of the hexagon and variable "letrinha" that is the character that is to be printed as the hollow hexagon:
Thanks in advance for any help :)
This is the code for the hollow hexagon in function of variable "ladoqh" that is the side of the hexagon and variable "letrinha" that is the character that is to be printed as the hollow hexagon:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
ladoqh = int ( input ()) letrinha = str ( input ()) totalhexagono = 2 * (ladoqh - 1 ) + ladoqh controlehex = 1 while controlehex< = totalhexagono : if controlehex = = 1 or controlehex = = totalhexagono: print ( " " * (ladoqh - 1 ) + letrinha * ladoqh + " " * (ladoqh - 1 )) if controlehex>ladoqh - 1 and controlehex< = 2 * ladoqh - ladoqh: print (letrinha + " " * (totalhexagono - 2 ) + letrinha) if controlehex> = 1 and controlehex<ladoqh - 1 : print ( " " * (ladoqh - 1 - controlehex) + letrinha + " " * ((ladoqh - 2 ) + 2 * (controlehex)) + letrinha + " " * (ladoqh - 1 - controlehex)) if controlehex> = 2 * ladoqh - 1 and controlehex<totalhexagono - 1 : print ( " " * (controlehex - totalhexagono + ladoqh) + letrinha + " " * (totalhexagono - 2 * (controlehex - totalhexagono + ladoqh + 1 )) + letrinha + " " * (ladoqh - 1 - controlehex)) controlehex + = 1 print () |