我是 python 循环的新手,我正在尝试创建一个循环迭代,我从 11 开始并找到前 42 个项

I am new to python loops and I am trying to create a loop iteration where I start with 11 and find the first 42 terms

start = 11
second = 8
third = 14
list = [start, second, third]
for number in range(42):
    start = start + second + third 
    print(f'{number+1}. {start}')

#using a for or while loop, I want to calculate the first 42 terms. Each term is calculated by adding the 3 previous terms 

Output should look like

  1. 11
  2. 8
  3. 14
  4. 33
  5. 55 etc...

enter code here

你非常接近,我看到你努力更新了你的代码几次。让我引导您完成初学者设置,您可以填写最后一位:

start = 11
second = 8
third = 14

my_list = [start, second, third]

# Loop
for i in range(42):
    print(i, my_list[i])
    # I only need to start doing something after the 3rd item, 2 because we count from 0
    if i >= 2:
        beginning_index = i - 2
        ending_index = i + 1

        # get my most recent three
        last_three = my_list[beginning_index:ending_index]
        # You can also do something called backward slicing instead of 
        # giving a range of items in a list to retrieve
        # This means give me the most recent 3 items
        # last_three = my_list[-3:]      

        # sum those three
        last_three = sum(last_three)

        # add the sum of last three to my list
        my_list.append(last_three)