Ask coding questions

← Back to all posts
add a title
DiegoCamacho3 (6)

hey my "else:" command isn't working. Idk why. I'm trying to make it so if someone is typing their name they say "yes" or "no" if they are satisfied with it. but if they type something else then I but "else:[new line] gameover = True" if anyone knows how to fix this. Just to clarify the language is Python

edit: will people please stop replying i got the answer, thanks. (sorry if this sounded a bit mean)

Comments
hotnewtop
KHZ (122)

@DiegoCamacho3 The answer I get to your question is this:

game = True

if (answer == "yes"):
  print("very nice to meet you,",name)

elif (answer == "no"):
  name = str(input("what is your name?"))

else:
  game = False
  print ("Goodbye!")

if (game == True):
  # Your rest of the statements
  pass

If this is not the answer then please elaborate your question!

DiegoCamacho3 (6)

@HammadZaeem thank you, i will try that out. if it doesn't work then i will let ya know

DiegoCamacho3 (6)

@HammadZaeem i am not sure why its not working. there is a red underline on the word "else:" maybe i will try re-opening relp.it

DiegoCamacho3 (6)

@HammadZaeem ok i tried reloading the IDE and it worked. i am dumb

KHZ (122)

@DiegoCamacho3 No problem. It sometimes happens (~ ̄▽ ̄)~

RYANTADIPARTHI (6019)

The else statement does work. If i don't type in anything like a yes or no, it just says please just answer yes. But if you are saying you want an input when they say something else try this:

if answer == "yes":
  print("nice to meet you,",name)

elif answer == "no":
  name = str(input("what is your name?"))
 
else:
  game = False
  print ("please just answer yes")
  answer = str(input("are you satisfied with your name? type: yes or no please: "))
  

And so on. put your code in. But you might want to use a while loop - while answer != yes:, and the code should repeat.
That should work

DiegoCamacho3 (6)

@RYANTADIPARTHI i fixed the thing a while ago but thanks

Coder100 (18057)

Working for me, just one thing, you don't need these parentheses

DiegoCamacho3 (6)

@Coder100 ye i know i deleted them, i took there code and edited it to match with the theme a little better

Coder100 (18057)

cool, so what's not working? @DiegoCamacho3