You are viewing a single comment's thread. Return to all comments →
thickness = int(input()) c = 'H'
for i in range(thickness): print((c * i).rjust(thickness - 1) + c + (c * i).ljust(thickness - 1))
for i in range(thickness + 1): print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
for i in range((thickness + 1) // 2): print((c * thickness * 5).center(thickness * 6))
for i in range(thickness): print(((c * (thickness - i - 1)).rjust(thickness) + c + (c * (thickness - i - 1)).ljust(thickness)).rjust(thickness * 6))
Seems like cookies are disabled on this browser, please enable them to open this website
Text Alignment
You are viewing a single comment's thread. Return to all comments →
This line is important - it reads the thickness from the test case input.
thickness = int(input()) c = 'H'
Top Cone
This correctly creates the pyramid for any thickness.
for i in range(thickness): print((c * i).rjust(thickness - 1) + c + (c * i).ljust(thickness - 1))
Top Pillars
The centering is calculated based on the thickness.
for i in range(thickness + 1): print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
Middle Belt
The width and centering also depend on the thickness.
for i in range((thickness + 1) // 2): print((c * thickness * 5).center(thickness * 6))
Bottom Pillars
This is identical to the top pillars.
for i in range(thickness + 1): print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
Bottom Cone
This creates the inverted pyramid and aligns it correctly to the right for any thickness.
for i in range(thickness): print(((c * (thickness - i - 1)).rjust(thickness) + c + (c * (thickness - i - 1)).ljust(thickness)).rjust(thickness * 6))