| Hosted by CoCalc | Download
Kernel: Python 3 (system-wide)
print()
#This function is the (row,col)^th entry of Pascal's triangle #The first row is 0, 0, 0, 1, 0, 0, 0, ... it makes it easier, since pas(0, col) is always defined def pas(row, col): if row==0: if col == 0: return 1 else: return 0 return pas(row-1, col-1) + pas(row-1, col)
pasc_triangle = [] user_input = 57 #int(input("How big do you want your triangle? Int only. ")) for row in range(user_input): triangle_row = [pas(row, col) for col in range(user_input)] # print(triangle_row) # triangle_row = [i for i in triangle_row if i!= 0] #removes the zeroes # print(triangle_row) pasc_triangle.append(triangle_row) for row in range(user_input): print(" "*(user_input - row),end=" ",sep=" ") for col in range(0,row+1): print('{0:5}'.format(pasc_triangle[row][col]),end=" ",sep=" ") print()
for row in range(user_input): print(" "*(user_input - row),end=" ",sep=" ") for col in range(0,row+1): print('{0:5}'.format(pasc_triangle[row][col]),end=" ",sep=" ") print()
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1
list(map(int,str(12345)))
[1, 2, 3, 4, 5]
print()
def pow_eleven_2four(): pow_arr = [] for i in range(5): power = 11 ** i pow_arr.append(power) print(list(map(int,str(pow_arr[i])))) return pow_arr pow_eleven_2four()
[1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1]
[1, 11, 121, 1331, 14641]
list(map(int,str(pow_arr)))
# https://www.sanfoundry.com/python-program-print-pascal-triangle/ n= 235 #int(input("Enter number of rows: ")) a=[] for i in range(n): a.append([]) a[i].append(1) for j in range(1,i): a[i].append(a[i-1][j-1]+a[i-1][j]) if(n!=0): a[i].append(1) for i in range(n): print(" "*(n-i),end=" ",sep=" ") for j in range(0,i+1): print('{0:6}'.format(a[i][j]),end=" ",sep=" ") print()
Enter number of rows: