Is there anyone who can help me code a program which gives an output like this
1
1
1 1
2 1
2 3 1
5 4 1
5 9 5 1
14 14 6 1
14 28 20 7 1
(It also can be in the opposite way)
I would like to adjust the numbers of lines. I coded the thing below but couldn’t get rid of the half of the triangle.
def pascal_tri(line_num): tri = [[1]] for i in range(1, line_num): prev_line = tri[-1] next_line = [1] for j in range(1, len(onceki_satir)): next_line.append(prev_line[j - 1] + prev_line[j]) next_line.append(1) tri.append(next_line) return tri def print_tri(tri): for line in tri: print(' '.join(map(str, line)).center(len(tri[-1]) * 2)) line_num = int(input("Enter the amount of lines: ")) pascal_triangle = pascal_tri(line_number) print_tri(pascal_triangle)
submitted by /u/l1qu1d57
[link] [comments]
r/learnpython Is there anyone who can help me code a program which gives an output like this 1 1 1 1 2 1 2 3 1 5 4 1 5 9 5 1 14 14 6 1 14 28 20 7 1 (It also can be in the opposite way) I would like to adjust the numbers of lines. I coded the thing below but couldn’t get rid of the half of the triangle. def pascal_tri(line_num): tri = [[1]] for i in range(1, line_num): prev_line = tri[-1] next_line = [1] for j in range(1, len(onceki_satir)): next_line.append(prev_line[j – 1] + prev_line[j]) next_line.append(1) tri.append(next_line) return tri def print_tri(tri): for line in tri: print(‘ ‘.join(map(str, line)).center(len(tri[-1]) * 2)) line_num = int(input(“Enter the amount of lines: “)) pascal_triangle = pascal_tri(line_number) print_tri(pascal_triangle) submitted by /u/l1qu1d57 [link] [comments]
Is there anyone who can help me code a program which gives an output like this
1
1
1 1
2 1
2 3 1
5 4 1
5 9 5 1
14 14 6 1
14 28 20 7 1
(It also can be in the opposite way)
I would like to adjust the numbers of lines. I coded the thing below but couldn’t get rid of the half of the triangle.
def pascal_tri(line_num): tri = [[1]] for i in range(1, line_num): prev_line = tri[-1] next_line = [1] for j in range(1, len(onceki_satir)): next_line.append(prev_line[j - 1] + prev_line[j]) next_line.append(1) tri.append(next_line) return tri def print_tri(tri): for line in tri: print(' '.join(map(str, line)).center(len(tri[-1]) * 2)) line_num = int(input("Enter the amount of lines: ")) pascal_triangle = pascal_tri(line_number) print_tri(pascal_triangle)
submitted by /u/l1qu1d57
[link] [comments]