while x <= 9:
result = usertype()
if result == 'Correct':
I am receiving an indentation error on the "t" of result in "result = usertype(). Can anybody explain this?
*EDIT I have tried rewriting it, and I checked to make sure that all of the indents are indeed indents and not spaces. Getting really frustrated and very confused now. I am thinking it might possibly be something in a previous line causing the problem.
*EDIT 2 Error copied from Command Prompt because IDLE doesn't work for me:
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
Solved! I'm not sure how, but I copy pasted my code into IDLE, untabified all regions then tabified again. I read somewhere else on SO to do that, so problem solved!
Here is the entire program:
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)
There isn't something wrong with the code as posted. But you may have mixed tabs and spaces in your file which causes Python to get confused about indentation. Check your text editor settings to see if you can highlight these characters.