使用Python,我目前正在尝试Project Euler问题#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只能处理其中一个。
修理,
使用在工具/脚本/中找到的reindent.py脚本
Python安装目录:
更改Python(.py)文件以使用4个空格的缩进且没有硬标签
字符。还修剪行尾的多余空格和制表符,并且
删除文件末尾的空行。同时确保最后一行结束
用换行符。看一下该脚本的详细用法
说明。
来自How to fix python indentation
关于python - Python:缩进错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32081490/