I'm getting TabError in python3 but not in python2

3614 views python
6

It's working totally fine in python2 but getting this error in python3- "TabError: inconsistent use of tabs and spaces in indentation" on statement "b=b+a". Already tried deleting spaces and checking for proper indentation.

def dice():
b=0
global a
a=random.randint(1,6)
    b=b+a
if(b>22):
    b=b-22 #Since 22 blocks in our board, one lap completion will result in 
a decrease of 22
#print b
return b

answered question

1 Answer

11

Tabs are required after colon syntax, both in if statements as well as function definitions. Try this:

def dice():
    b=0
    global a
    a=random.randint(1,6)
    b=b+a
    if(b>22):
        b=b-22 #Since 22 blocks in our board, one lap completion will result in a decrease of 22
    #print b
    return b

posted this

Have an answer?

JD

Please login first before posting an answer.