while x <= 9:
result = usertype()
if result == 'Correct':
我对结果的“结果=用户类型的“T”()。任何人都可以解释这种接收缩进错误?Python的缩进错误while循环
*编辑 我曾尝试重写它,我检查确认所有的缩进确实是缩进而不是空格,现在变得非常沮丧和非常困惑,我想这可能是上一行中导致问题的东西。从命令提示符复制错误,因为IDLE不适用于我:
File "<stdin>", line 5
result = usertype()
^
IndentationError: expected an indented block
>>> if result == 'Correct':
File "<stdin>", line 1
if result == 'Correct':
^
IndentationError: unexpected indent
>>> x = x + 1
File "<stdin>", line 1
x = x + 1
^
IndentationError: unexpected indent
>>> y = y + 5
File "<stdin>", line 1
y = y + 5
^
IndentationError: unexpected indent
>>> else:
File "<stdin>", line 1
else:
^
IndentationError: unexpected indent
>>> x = x + 1
File "<stdin>", line 1
x = x + 1
^
IndentationError: unexpected indent
>>> y = y - a2
File "<stdin>", line 1
y = y - a2
^
IndentationError: unexpected indent
>>> return y
File "<stdin>", line 1
return y
^
IndentationError: unexpected indent
解决! 我不知道如何,但我复制粘贴我的代码到空闲,untabified所有地区,然后再次制表符。我在其他地方读过这么做,所以问题解决了!
这里是整个程序:
import random
def usertype(raw_input):
randletter = random.choice('qwer')
print randletter
userinput = raw_input('')
if userinput == randletter:
return 'Correct'
else:
return 'Incorrect'
def usertypetest(raw_input):
x=0
y=0
while x <= 9:
result = usertype()
if result == 'Correct':
x = x + 1
y = y + 5
else:
x = x + 1
y = y - a2
return y
print usertypetest(raw_input)
你在混合标签和空格吗?这通常是这些类型错误的原因。 – iCodez
是...从...按“输入”键入并键入新代码 –
我重写了代码,仍然收到此错误。我现在将发布整个程序。 – Bretsky