杨辉三角形Python实现

#杨辉三角形
def digui(a,b):
    num = (1 if(b==1 or a==b)else (digui(a-1,b-1)+digui(a-1,b)))
    return num

x = int(input())
for i in range(1,x+1):
    for j in range(1,i+1):
        print(digui(i,j),end=' ')
    print('')

你可能感兴趣的:(python,蓝桥杯)