Write a program to construct and print Pascal’s Triangle for a given number of rows. The user should be prompted to enter a positive integer indicating the number of rows, and if the user provides an invalid input the program should prompt for additional input until valid input is received.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
def main():
main()
def positive_input():
x = int(input("Enter a positive integer: "))
while x <= 0:
print("Invalid input!")
x = int(input("Enter a positive integer: "))
return x
def main():
main()
def positive_input():
x = int(input("Enter a positive integer: "))
while x <= 0:
print("Invalid input!")
x = int(input("Enter a positive integer: "))
return x
def main():
n = positive_input()
main()
def main():
n = positive_input()
row = [1]
print(row)
def main():
n = positive_input()
row = [1]
print(row)
for i in range(1, n):
# update row
print(row)
def update_row(row):
def update_row(row):
i = 0
while i < len(row):
# use list elements
i = i + 1
def update_row(row):
i = 0
new_row = [1]
while i < len(row):
# use list elements
i = i + 1
def update_row(row):
i = 0
new_row = [1]
while i < len(row):
new_row.append(row[i] + row[i + 1])
i = i + 1
def update_row(row):
i = 0
new_row = [1]
while i < len(row):
new_row.append(row[i] + row[i + 1])
i = i + 1
new_row.append(1)
return new_row
def positive_input():
x = int(input("Enter a positive integer: "))
while x <= 0:
print("Invalid input!")
x = int(input("Enter a positive integer: "))
return x
def update_row(row):
i = 0
new_row = [1]
while i < len(row):
new_row.append(row[i] + row[i + 1])
i = i + 1
new_row.append(1)
return new_row
def main():
n = positive_input()
row = [1]
print(row)
for i in range(1, n):
row = update_row(row)
print(row)
main()
def update_row(row):
i = 0
new_row = [1]
while i < len(row):
new_row.append(row[i] + row[i + 1])
i = i + 1
new_row.append(1)
return new_row
def update_row(row):
i = 0
new_row = [1]
while i < len(row) - 1:
new_row.append(row[i] + row[i + 1])
i = i + 1
new_row.append(1)
return new_row
def positive_input():
x = int(input("Enter a positive integer: "))
while x <= 0:
print("Invalid input!")
x = int(input("Enter a positive integer: "))
return x
def update_row(row):
i = 0
new_row = [1]
while i < len(row) - 1:
new_row.append(row[i] + row[i + 1])
i = i + 1
new_row.append(1)
return new_row
def main():
n = positive_input()
row = [1]
print(row)
for i in range(1, n):
row = update_row(row)
print(row)
main()