问答详情
源自:9-1 什么是函数

请问哪里错了

num_list = []

    n = 1

    while n <= 100:

        p = n * n

        num_list.append(p)

        n + 1

   s = sum(num_list)

print(s)


报错

 File "index.py", line 2

    n = 1




提问者:慕沐8078606 2023-10-12 17:18

个回答

  • 慕九州9574257
    2023-10-24 17:39:43

    缩进的问题,加上n+1要改为n+=1

    正确如下:

    num_list = []


    n = 1


    while n <= 100:


        p = n * n


        num_list.append(p)


        n += 1


    s = sum(num_list)


    print(s)