Untitled

 avatar
unknown
python
2 years ago
541 B
3
Indexable
import sys

# Ugly, don't do it that way in production code, use argparse instead
assert len(sys.argv) > 1, 'No WIDTH provided'
WIDTH = int(sys.argv[1])
assert (WIDTH % 2) == 1, 'WIDTH must be odd number!'

# Alternatively just hard-code the const (ensure it's odd)
# WIDTH = 7

def star_line_string(stars, width):
    spaces = (WIDTH - i) // 2
    return f"{' ' * spaces}{'*' * i}{' ' * spaces}"

for i in range(1, WIDTH + 1, 2):
    print(star_line_string(i, WIDTH))

for i in range(WIDTH - 2, 0, -2):
    print(star_line_string(i, WIDTH))