Skip to content
Sign upLog in
← Back to Community

TabError: inconsistent use of tabs and spaces in indentation

Profile icon
adsarebbbad

at the bottom, somehow the enter() code gives an error

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
EshaHaldar
Profile icon
Tanfukaiphilip
Profile icon
hotuan2301
Profile icon
SANTIAGO-ALBERT
Profile icon
dabs364
Profile icon
adsarebbbad
Comments
hotnewtop
Profile icon
Coder100

That is because on that line you are using tabs:

image

In the future, for that, hit ctrl+f, click on .* (regex option) and then for the first input box, type in \t and the second, (two spaces).

Afterwords you will be all set!

Profile icon
Viviotic

@Coder100
AMAZING! You saved me over an hour with this. THANK YOU!!

Profile icon
Coder100
Profile icon
DankPricer

@Coder100
didnt work :/

Profile icon
MareksZuks

@Coder100
Thank you so much! For school i was making a game with 50/50 chances then this indent thing happened an thanks to you i could fix it and keep going. Thank you so much!

Profile icon
VihaanMody

@Coder100
I doesn't work at all. This just changes tab spaces. The error still comes and doesn't stop.

image

Profile icon
SixBeeps

That line is indented with tabs, but the rest of the stuff is indented with spaces.

Profile icon
PattanAhmed

@adsarebbbad
Hi,
It's clear as the error itself is referring to the error TabError: inconsistent use of tabs and spaces in indentation.

Anyways, here is the correct code:-
Replace all your code with this:-

from colored import fg, attr import time, sys from time import sleep import os def sp(str): for i in str: sys.stdout.write(i) sys.stdout.flush() if ((i != "\n") and (i != ":")): time.sleep(0.09) else: time.sleep(0.6) randomUsername = input(fg('red')+ "Type a random username\n>>") os.system("clear") def enter(): input(fg('yellow')+"Press enter") os.system("clear") while True: sp(fg('red')+"hello " + randomUsername) userInput = input(""" [1] Go to shop [2] Play\n>>""") if (userInput == '1'): os.system("clear") userInput = input(""" Shop: [1] Free: Wooden Sword [2] 10 Coins: Stone Sword [3] Back\n""") if(userInput == '1'): sp(fg('blue')+"You now have 1 wooden sword") enter() elif(userInput == '2'): os.system("clear") userInput = input(""" You've decided to play [1] Go to the lands [2] Back\n""") if(userInput == '1'): sp(fg('yellow')+"You have arrived at the lands") enter() os.system("clear")

That's it
Thanks!

Hope this helps

Profile icon
adsarebbbad
Profile icon
PattanAhmed

@adsarebbbad
Welcome!
Happy to help!

Profile icon
adsarebbbad

well,

@Coder100
's answer is more effective
@PattanAhmed

Profile icon
PattanAhmed