python_exercises/thinkcspy/Chapter-16-Exercises/pascal.py

26 lines
558 B
Python
Raw Normal View History

2023-12-22 02:23:49 -07:00
def pascal(row):
num = 0
if row < 0:
return
2023-12-22 04:02:11 -07:00
else:
2023-12-22 02:23:49 -07:00
for i in range(row+1):
2023-12-22 04:02:11 -07:00
spaces = (" "*(row-i))
nums = f"{getbinomial(num, i)} "
print(spaces + nums + spaces)
# if row == 0 or 1: num = 1
# the first and last instance of i always == 1
#elif row % 2 == 0:
# increase until the middle number then decrease
#elif row % 2 == 1:
# increase until the halfway point, then decrease
def getbinomial(num, iters):
return f"{num+iters} " * iters
2023-12-22 02:23:49 -07:00
pascal(8)