# This program draws an hourglass figure # of characters and numbers using nested loops. # This version is an interactive program that uses parameters. # Prints a solid line of dashes. def draw_line(sub_height): print("+", end="") print("-" * (2 * sub_height), end="") print("+") # Produces the top half of the hourglass figure. def draw_top(sub_height): for line in range(1, sub_height + 1): print("|", end="") print(" " * (line - 1), end="") print("\\", end="") for i in range(1, 2 * sub_height + 1 - 2 * line): print(i, end="") print("/", end="") print(" " * (line - 1), end="") print("|") # Produces the bottom half of the hourglass figure. def draw_bottom(sub_height): for line in range(1, sub_height + 1): print("|", end="") print(" " * (sub_height - line), end="") print("/", end="") for i in range(2 * line - 2, 0, -1): print(i, end="") print("\\", end="") print(" " * (sub_height - line), end="") print("|") def main(): sub_height = int(input("Figure height? ")) draw_line(sub_height) draw_top(sub_height) draw_bottom(sub_height) draw_line(sub_height) main()