杨辉三角

def listP(row, col):

if (row == col or col == 0):
    return 1
else:
    return listP(row - 1, col - 1) + listP(row - 1, col)

def yanghui():

n = 10
strL = ""
for i in range(0, n):
    for j in range(0, i + 1):
        strL += str(listP(i, j)) + "\t"
        if i == j:
            strL += "\n"
print(strL)

你可能感兴趣的:(杨辉三角)