-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_alignment.py
More file actions
38 lines (31 loc) · 1.4 KB
/
text_alignment.py
File metadata and controls
38 lines (31 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/python3
# Python String Alignment Challenge Solution
# Author: Audity Ghosh
# Date: 30 March, 2020
# Description:
# This script generates the HackerRank Logo of variable thickness.
# The logo consists of a top cone, top pillars, middle belt, bottom pillars, and bottom cone.
# The thickness is an odd number and controls the size of the logo.
# Read the input thickness, which must be an odd number
thickness = int(input()) # This must be an odd number
c = 'H'
# Top Cone
for i in range(thickness):
# Align the characters and print the top cone of the logo
print((c * i).rjust(thickness - 1) + c + (c * i).ljust(thickness - 1))
# Top Pillars
for i in range(thickness + 1):
# Center-align the pillars to form the top portion of the logo
print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
# Middle Belt
for i in range((thickness + 1) // 2):
# Center-align the middle belt
print((c * thickness * 5).center(thickness * 6))
# Bottom Pillars
for i in range(thickness + 1):
# Center-align the bottom pillars
print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
# Bottom Cone
for i in range(thickness):
# Align the characters and print the bottom cone of the logo
print(((c * (thickness - i - 1)).rjust(thickness) + c + (c * (thickness - i - 1)).ljust(thickness)).rjust(thickness * 6))