【发布时间】:2019-05-28 00:24:56
【问题描述】:
我怎样才能生成下面的金字塔(第一行和第二行是预先施加的)?
1
1 4 1
1 5 6 5 1
1 6 12 16 12 6 1
这是我迄今为止尝试过的,但没有奏效:
def main():
first_row = [1] # given in the question
second_row = [1, 4, 1] # given in the question
sum = 0
n = int(input("Enter number of rows: "))
list_of_rows = list()
list_of_rows.append(first_row)
list_of_rows.append(second_row)
for i in range(2, n):
list_of_rows.append([])
for j in range(0, 2*i+1): # each row is 2 digits bigger than the previous
list_of_rows[i].append(sum)
print(list_of_rows)
【问题讨论】:
-
你没有改变总和