Page 630 - ComputerScience_Class_11
P. 630
Multiplication Table for 10:
10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100
39. Write a program to generate Pascal’s triangle.
Program 39.py
File Edit Format Run Options Window Help
rows = int(input("Enter the number of rows: "))
triangle = []
i = 0
while i < rows:
row = [1] * (i + 1)
j = 1
while j < i:
row[j] = triangle[i - 1][j - 1] + triangle[i - 1][j]
j += 1
triangle.append(row)
i += 1
for row in triangle:
print(" ".join(map(str, row)).center(2 * rows))
The output of the preceding program is as follows:
Output
Enter the number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
628 Touchpad Computer Science (Ver. 3.0)-XI

