2014-06-26 50 views
1
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) 
+2

你在混合标签和空格吗?这通常是这些类型错误的原因。 – iCodez

+0

是...从...按“输入”键入并键入新代码 –

+0

我重写了代码,仍然收到此错误。我现在将发布整个程序。 – Bretsky

回答

5

张贴没有什么问题的代码。但是,您的文件中可能混合了制表符和空格,导致Python对缩进感到困惑。检查您的文本编辑器设置,看看您是否可以突出显示这些字符。

+0

我查过了,他们都是标签。我重写了错误的地方,但没有运气。 – Bretsky