This is my code:
import math
def binomial(n,k):
if k == n:
print(1)
elif k == 1:
print(n)
elif k > n:
print(0)
else:
a=math.factorial(n)
b=math.factorial(k)
c=math.factorial(n-k)
BIN = int(a/(b*c))
print(BIN, end=' ')
#print ("Binomial of (n,k) is : ",BIN)
return
def pascal(n):
list=[n]
for n in range(1,n+1):
#print (list)
list.append([])
list[n].append(1)
for k in range(0,n+1):
list[n].append(binomial(n,k))
#newlist.append(list[-1])
return
pascal(20)
'''for x in range (1,n+1):
for y in range (0,x+1):
print (binomial(x,y),)
#print (' ')'''
x=int(input("enter n: "))
y=int(input("enter k: "))
binomial(n=x,k=y)
The terms returned are technically correct, but instead of forming a triangle shape, they were printed two terms each line. I would like to know how to fix the shape as appropriate.