Elif statement proble

Problem description:
when i run my repl it shows me an error
my code

tvShow = input("What is your favorite tv show? ")
if tvShow == "ninjago":
  print("i love it too")
  faveCharacter = input("Who is your favorite character? ")
	if faveCharacter == "zane":
  	print("technological guy")
	elif faveCharacter == "jay":
  	print("such a joker")
	elif faveCharacter == "kai":
  	print("hot, but cool, 'hairstyle'")
	elif faveCharacter == "nya":
  	print("")
	elif faveCharacter == "cole":
  	print("such a strength, sometimes afraid of dragons")
	elif faveCharacter == "lloyd":
  	print("weird, wants to be like his father, but his greatest fear is that")
	elif faveCharacter == "wu" or faveCharacter == "sensei wu":
  	print("an old teacher")
	elif faveCharacter == "garmadon":
  	print("a shapeshifter, a normal man then an evil, black skin, four arms with hands and fingers, again a normal sensei who doesn't fight, then a fake serpentine, and after that a real one, then a ghost, after that a dead soul, and then a reborn man with four arms, a great evil with the element of destruction, fighting with ninjas, and then an oni, helping ninjas destroy other onis and Omega, then spreading chaos over Ninjago, and then being a plant carer, then oni, then normal again, oni again, normal evil form")

Expected behavior:
it should ask me my favorite tv show if i type ninjago it should ask me about my favorite charecter

Actual behavior:
it shows me this error

 File "main.py", line 7
    elif faveCharacter == "jay":
                               ^
TabError: inconsistent use of tabs and spaces in indentation

Bug appears at this link:
https://replit.com/@sbzm123/day-7100-days

Browser:
google chrome
OS:
windows 10
Device (Android, iOS, NA leave blank):
toshiba laptop
Plan (Free, Hacker, Pro Plan):
free

this is the code (somehow the code was unindented)

tvShow = input("What is your favorite tv show? ")
if tvShow == "ninjago":
  print("i love it too")
  faveCharacter = input("Who is your favorite character? ")
	if faveCharacter == "zane":
  	print("technological guy")
	elif faveCharacter == "jay":
  	print("such a joker")
	elif faveCharacter == "kai":
  	print("hot, but cool, 'hairstyle'")
	elif faveCharacter == "nya":
  	print("")
	elif faveCharacter == "cole":
  	print("such a strength, sometimes afraid of dragons")
	elif faveCharacter == "lloyd":
  	print("weird, wants to be like his father, but his greatest fear is that")
	elif faveCharacter == "wu" or faveCharacter == "sensei wu":
  	print("an old teacher")
	elif faveCharacter == "garmadon":
  	print("a shapeshifter, a normal man then an evil, black skin, four arms with hands and fingers, again a normal sensei who doesn't fight, then a fake serpentine, and after that a real one, then a ghost, after that a dead soul, and then a reborn man with four arms, a great evil with the element of destruction, fighting with ninjas, and then an oni, helping ninjas destroy other onis and Omega, then spreading chaos over Ninjago, and then being a plant carer, then oni, then normal again, oni again, normal evil form")

you have to indent the print statements and every line of code inside of the if, else, and elif blocks since python blocks are based off of indentations
example:

if faveCharacter == "zane":
  	print("technological guy")
elif faveCharacter == "jay":
  	print("such a joker")
1 Like

You must use either all spaces (preferred) or all tabs in your indentations, not a mixture of both.
You should click “Format main.py”, the small symbol in your main.py tab in the editor to fix the tabs and spaces.
This is, in fact, the only problem. Your indentation levels are fine (in your post, tabs are 4 spaces long instead of 2).

1 Like

Ignore my previous code, it was overkill :skull::

tvShow = input("What is your favorite TV show? ")

if tvShow.lower() == "ninjago":
    print("I love it too!")
    faveCharacter = input("Who is your favorite character? ").lower()

    character_info = {
        "zane": "a technological genius",
        "jay": "a humorous and playful character",
        "kai": "fiery and cool, with a unique hairstyle",
        "nya": "a strong and skilled ninja",
        "cole": "a formidable and occasionally dragon-shy ninja",
        "lloyd": "an interesting character striving to follow in his father's footsteps",
        "wu": "a wise and experienced teacher",
        "garmadon": "a complex character who transforms from a normal man to an evil entity with multiple forms, including a serpentine, a ghost, and a being of chaos"
    }

    character_description = character_info.get(faveCharacter, "Character information not available.")
    print(character_description)
else:
    print("I'm not familiar with that TV show.")

why are you using lambdas though? (also why u have an f-string containing just a string value?)
both fixed

are you talking about where character_description is printed?

Shouldn’t that be:

print(character_description)
1 Like

I’d suggest to implement a while loop to allow the user to try again if they enter an unrecognized TV show or character.

Oops, yeah I just fixed that :sob: