慕沐8078606
2023-10-12 17:18
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
缩进的问题,加上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)
Python3 入门教程(新版)
154161 学习 · 1075 问题
相似问题