当我的缩进正确时,为什么 python 给我一个缩进不正确的错误?
Why is python giving me an error for improper indentation when my indentation is correct?
这是我收到的错误信息:
File "main.py", line 15
while True:
^
IndentationError: unindent does not match any outer indentation level
这是我的完整代码:
import wikipedia
from colorama import Fore, Style, Back
y = input("tell me what you want ")
z = int(input("how many sentences "))
try:
text = wikipedia.summary(y, sentences=z)
print('')
print("---Text---")
print(text)
print("----------")
print(len(text.split()),"words.")
except:
print(Fore.RED + "ERROR)
while True:
print("\a")
您能解释一下为什么会这样吗?我正在在线使用 Repl ide.
答案是我混淆了制表符和空格。您不应该同时使用两者,因为可能会发生此错误。
在 python 中编码时,注意缩进方式非常重要。当然,您可以使用制表符或 space,但始终确保坚持使用其中之一,不要将它们混合在一起。
你这次好像没做。删除缩进并重新缩进。应该可以正常工作。
这是我收到的错误信息:
File "main.py", line 15
while True:
^
IndentationError: unindent does not match any outer indentation level
这是我的完整代码:
import wikipedia
from colorama import Fore, Style, Back
y = input("tell me what you want ")
z = int(input("how many sentences "))
try:
text = wikipedia.summary(y, sentences=z)
print('')
print("---Text---")
print(text)
print("----------")
print(len(text.split()),"words.")
except:
print(Fore.RED + "ERROR)
while True:
print("\a")
您能解释一下为什么会这样吗?我正在在线使用 Repl ide.
答案是我混淆了制表符和空格。您不应该同时使用两者,因为可能会发生此错误。
在 python 中编码时,注意缩进方式非常重要。当然,您可以使用制表符或 space,但始终确保坚持使用其中之一,不要将它们混合在一起。
你这次好像没做。删除缩进并重新缩进。应该可以正常工作。