Ask coding questions

← Back to all posts
need help
ethanheys (38)

https://repl.it/@ethanheys/AquaDopeyMice
pls help i dont know whats wrong with the elif

Answered by heyitsmarcus (287) [earned 5 cycles]
View Answer
Commentshotnewtop
heyitsmarcus (287)

Hey @ethanheys,

You just needed to have the right indentation in your code. Remember that elif and else attach to the same indentation level, so you were doing massive if, elif and else.

So, I put the tv and lines that go with tv into their own indentation level, so that they have their own set of if, elif, and else.

This part just needed to be indented like so:

user_answer = input("are you girl or boy ").lower().strip()
if user_answer == "boy":
  tv = input("do you like tv ").lower().strip()
  if tv == "yes":
      print("cool")
  elif tv == "no":
      no =str(input("well what do you like"))
      print('well i dont really like',no,'but ok')
  else:
      print("Error: must be yes or no")
elif user_answer == "girl":
    print("ok")
else:
    print("Error: must be girl or boy")

If this solves your problem, please consider marking my answer as the accepted answer. I will continue to answer questions you might have.