我的变量不断出现语法错误。我应该怎么办
My variable keeps getting a syntax error. What should i do
变量 x 总是显示为语法错误。表示要生成的质数个数
x=501
while x<1 or x>500:
NoNos=int(input("Number of Prime Numbers"))
if x<1:
print("The number has to be greater than 1")
if x>500:
print("The number has to be lesser than 500")
PrimeNo=2
PrimeNos=[]
While not x==0:
if PrimeNo==2:
PrimeNos=PrimeNos+[PrimeNo]
x=x-1
PrimeNo=PrimeNo+1
continue
for divisor in the range (2,PrimeNo-1):
if not PrimeNo%divisor=0:
x=x-1
PrimeNos=PrimeNos+[PrimeNo]
print(PrimeNos)
我修正了你代码中的一些错误
- 同时 => 同时
- 范围=>范围
- PrimeNo%divisor=0: => PrimeNo%divisor==0:
=========================================== ==========================
x=501
while x<1 or x>500:
NoNos=int(input("Number of Prime Numbers"))
if x<1:
print("The number has to be greater than 1")
if x>500:
print("The number has to be lesser than 500")
PrimeNo=2
PrimeNos=[]
while not x==0:
if PrimeNo==2:
PrimeNos=PrimeNos+[PrimeNo]
x=x-1
PrimeNo=PrimeNo+1
continue
for divisor in range (2,PrimeNo-1):
if not PrimeNo%divisor == 0:
x=x-1
PrimeNos=PrimeNos+[PrimeNo]
print(PrimeNos)
$ python test.py
File "test.py", line 11
While not x==0:
^
SyntaxError: invalid syntax
这是 Python 中的错误。插入符号应指向 'While' 中的大写字母 'W'。您必须拼写 'while',所有字母都小写。
你还有其他错别字:
File "test.py", line 17
for divisor in the range (2,PrimeNo-1):
^
SyntaxError: invalid syntax
此处插入符号应指向 'the',应将其删除。
File "test.py", line 18
if not PrimeNo%divisor=0:
^
SyntaxError: invalid syntax
这次插入符号在正确的位置! '=' 需要是 '=='。
在我进行了所有这些更改之后,您的程序仍然无法工作,但剩下的问题似乎不是语法问题。
(我在错位的插入符号上归档了 http://bugs.python.org/issue23518。)
变量 x 总是显示为语法错误。表示要生成的质数个数
x=501
while x<1 or x>500:
NoNos=int(input("Number of Prime Numbers"))
if x<1:
print("The number has to be greater than 1")
if x>500:
print("The number has to be lesser than 500")
PrimeNo=2
PrimeNos=[]
While not x==0:
if PrimeNo==2:
PrimeNos=PrimeNos+[PrimeNo]
x=x-1
PrimeNo=PrimeNo+1
continue
for divisor in the range (2,PrimeNo-1):
if not PrimeNo%divisor=0:
x=x-1
PrimeNos=PrimeNos+[PrimeNo]
print(PrimeNos)
我修正了你代码中的一些错误
- 同时 => 同时
- 范围=>范围
- PrimeNo%divisor=0: => PrimeNo%divisor==0:
=========================================== ==========================
x=501
while x<1 or x>500:
NoNos=int(input("Number of Prime Numbers"))
if x<1:
print("The number has to be greater than 1")
if x>500:
print("The number has to be lesser than 500")
PrimeNo=2
PrimeNos=[]
while not x==0:
if PrimeNo==2:
PrimeNos=PrimeNos+[PrimeNo]
x=x-1
PrimeNo=PrimeNo+1
continue
for divisor in range (2,PrimeNo-1):
if not PrimeNo%divisor == 0:
x=x-1
PrimeNos=PrimeNos+[PrimeNo]
print(PrimeNos)
$ python test.py
File "test.py", line 11
While not x==0:
^
SyntaxError: invalid syntax
这是 Python 中的错误。插入符号应指向 'While' 中的大写字母 'W'。您必须拼写 'while',所有字母都小写。
你还有其他错别字:
File "test.py", line 17
for divisor in the range (2,PrimeNo-1):
^
SyntaxError: invalid syntax
此处插入符号应指向 'the',应将其删除。
File "test.py", line 18
if not PrimeNo%divisor=0:
^
SyntaxError: invalid syntax
这次插入符号在正确的位置! '=' 需要是 '=='。
在我进行了所有这些更改之后,您的程序仍然无法工作,但剩下的问题似乎不是语法问题。
(我在错位的插入符号上归档了 http://bugs.python.org/issue23518。)