关于作者

Discuss / Python / SyntaxError: invalid syntax?

SyntaxError: invalid syntax?

Topic source

Chefback

#1 Created at ...

L = [] n = 1 while n <= 99: L.append(n) n = n + 2 print(L)

错误是SyntaxError: invalid syntax??

安迪博德

#2 Created at ...

你这段代码,如果全部粘贴到cmd中,会报错,因为会把print语句当成了while的内部语句(三个点),而又缺少缩进。 我也是试了半天才发现的……

失业你介夫

#3 Created at ...

2#说得对!

迷茫的老九

#4 Created at ...
L = []
n = 1
while n <= 99:
    L.append(n)
    n = n + 2

这样就行,一是print是多余,二是及时你的缩进也不对

ghostdog-_-

#5 Created at ...

L=[] n = 1 while n<=99: L.append(n) n = n +2 print(L) 并没有错哇,你是不是直接copy的,这样可能会有格式错误,下面是结果 ================ RESTART: C:/Users/hejiaxiong/Desktop/test.py ================ [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.