Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def p_tri(x):
- if x == 0:
- return []
- elif x == 1:
- return [[1]]
- else:
- newrow = [1]
- pyr = p_tri(x-1)
- lastrow = pyr[-1]
- cnt = len(lastrow)-1
- rcs(lastrow, newrow, cnt)
- newrow += [1]
- pyr.append(newrow)
- return pyr
- def rcs(lastrow, newrow, cnt):
- if cnt == 0:
- return newrow
- else:
- newrow.append(lastrow[cnt-1] + lastrow[cnt])
- return rcs(lastrow, newrow, cnt-1)
- x = input("Enter a number: ")
- x = int(x)
- if 0 <= x <= 10:
- n = p_tri(x)
- print(*n, sep="\n")
- else:
- print("no ser.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement