32 lines
747 B
Python
32 lines
747 B
Python
|
from cs50 import get_int
|
||
|
|
||
|
|
||
|
# asks user for height input
|
||
|
def user_input():
|
||
|
user_height = 0
|
||
|
while user_height < 1 or user_height > 8:
|
||
|
user_height = get_int("Height: ")
|
||
|
if user_height < 1 or user_height > 8:
|
||
|
print("Input height from 1 to 8.")
|
||
|
|
||
|
return user_height
|
||
|
|
||
|
|
||
|
# creates spacing in the pyramid
|
||
|
def spacing(offset):
|
||
|
for space in range(offset):
|
||
|
print(" ", end="")
|
||
|
|
||
|
|
||
|
# creates a pyramid
|
||
|
height = user_input()
|
||
|
for i in range(1, height + 1, 1):
|
||
|
spacing(height - i)
|
||
|
# creates first left side, than space, than right side of pyramid
|
||
|
for k in range(1, 3, 1):
|
||
|
for j in range(1, i + 1, 1):
|
||
|
print("#", end="")
|
||
|
if k == 1:
|
||
|
print(" ", end="")
|
||
|
print()
|