使用Python,我目前正在尝试Project Euler Problem #7,它要求找到第10001个素数,但是在运行我的代码时遇到错误
"File "<stdin>", line 3
TestedValue = 2
^
IndentationError: unexpected indent
Unknown error."
我假设这不是唯一面临该错误的行,但这是弹出的第一行,知道我做错了什么吗?谢谢!
代码:
def PrimeNum(NumIn):
PrimeNumCounter = 0
TestedValue = 2
if TestedValue == 2:
PrimeNumCounter += 1
TestedValue += 1
else:
while PrimeNumCounter != NumIn-1
for i in range(2, TestedValue):
Prelim = 0
if TestedValue % i != 0:
Prelim += 1
elif TestedValue % i == 0:
Prelim = 0
if Prelim > 0:
PrimeNumCounter += 1
if PrimeNumCounter == NumIn-1:
for i in range(2, TestedValue):
Prelim = 0
if TestedValue % i != 0:
Prelim += 1
elif TestedValue % i == 0:
Prelim = 0
if Prelim > 0:
print TestedValue
最佳答案
您的文本编辑器正在混合空格和缩进。 Python 只能处理其中之一。
要修复,
Use the reindent.py script that you find in the Tools/scripts/ directory of your Python installation:
Change Python (.py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files. Also ensure the last line ends with a newline. Have a look at that script for detailed usage instructions.
关于Python:缩进错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32081490/