Search code examples
pythonif-statementindentation

Python not jumping into "else" condition


Good morning,

This is my 1st post here & Im only dabbing my feet in programming pool so please be gentle :)

As it currently stands, I have to fulfill 2 conditions (sadcat & great == yes). What I want instead is to jump straight to else ( 'Why did you even start this game in the first place? This is a rhetorical question btw.'), if the 1st condition is not ulfilled (sadcat == something else than 'yes') I have no idea why doesnt this work... Indentation seems to be OK to me. Any help is appreciated

sadcat = input('Do you like war? ')
great = input ('That\'s great but are you also a cat? ')


if sadcat == 'yes':
    if great == 'yes':
      print('ok I have no more questions')
    else:
      print('Not a cat ? How do you even live with yourself.')
else:
  print('Why did you even start this game in the first place? This is a rhetorical question btw.', end=" ")

Solution

  • If you want the "game" to end if the "player" doesn't like war, then the first if should be right after the first question

    sadcat = input('Do you like war? ')
    if sadcat == 'no':
        print('Why did you even start this game in the first place? This is a rhetorical question btw.', end=" ")
        exit()
    
    great = input ('That\'s great but are you also a cat? ')
    if great == 'yes':
        print('ok I have no more questions')
    else:
        print('Not a cat ? How do you even live with yourself.')