(https://i.stack.imgur.com/v9sj1.png)
Hi all, I am currently trying to calculate and print out the pascals extended triangle for negative numbers (-1, -2, ..., -10)
I am aware of the math library but I want to try without the usage of libraries, recursion, lists, string and the other related operations.
the ideal output should be something like this:
(https://i.stack.imgur.com/fnmpL.png)
So I have went ahead and coded up my own factorial function, and a attempt at coding the nCk function:
def factorial(n):
result = 1
for i in range(1, n+1):
result = i
return result
def n_choose_k(n, k):
return factorial(n) / (factorial(k) * factorial(n-k))
when I tried to validate if it works or not, I picked out a value from the sample output from above, where k equals to 6 and n equals to -7
def factorial(n):
result = 1
for i in range(1, n+1):
result = i
return result
def n_choose_k(n, k):
return factorial(n) / (factorial(k) * factorial(n-k))
print(n_choose_k(-7, 6))
^^ what I ran in my program.
the result should be 924 but instead I got 0.166.
Am I calling the functions wrong? Is there an error in my code?
I am a super noob in terms of programming, much feedback is appreciated.
*sidenote im not sure why my images arent showing, also a noob for this website!