简体   繁体   中英

I'm getting TabError in python3 but not in python2

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM