Python Forum
Blank spaces in right side
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blank spaces in right side
#1
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:
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()
Thanks in advance for any help :)
Reply


Messages In This Thread
Blank spaces in right side - by fernando_santiago18 - Sep-06-2019, 08:41 PM
RE: Blank spaces in right side - by ThomasL - Sep-07-2019, 12:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seven Segment Display - QUERY on Multi-line side-by-side printing output ajayachander 3 4,864 Mar-13-2020, 07:02 AM
Last Post: ajayachander
  exception in side if clause sbabu 6 3,000 Feb-15-2020, 08:44 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020