From 37aef8562988c7b77590712ae2230589d94f5aa6 Mon Sep 17 00:00:00 2001 From: lolabird Date: Fri, 22 Dec 2023 04:02:11 -0700 Subject: [PATCH] Get formatting to work with function --- thinkcspy/Chapter-16-Exercises/pascal.py | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/thinkcspy/Chapter-16-Exercises/pascal.py b/thinkcspy/Chapter-16-Exercises/pascal.py index 95e35cc..31baed7 100644 --- a/thinkcspy/Chapter-16-Exercises/pascal.py +++ b/thinkcspy/Chapter-16-Exercises/pascal.py @@ -3,17 +3,23 @@ def pascal(row): if row < 0: return - else: - if row <= 2: - num = 1 - #elif row > 2 print - + else: for i in range(row+1): - if i == 0: - continue - else: - print((" "*(row-i)) + (f" {num} "*i) + (" "*(row-i))) - + 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 pascal(8)