Skip to content
← Back to Community
add a title
Profile icon
DiegoCamacho3

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] [indent] 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)

Voters
Profile icon
SomaiaSultana2
Profile icon
Dominicl645
Profile icon
DiegoCamacho3
Comments
hotnewtop
Profile icon
KHZ

@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!

Profile icon
DiegoCamacho3

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

Profile icon
KHZ
Profile icon
DiegoCamacho3

@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

Profile icon
DiegoCamacho3

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

Profile icon
KHZ

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

Profile icon
RYANTADIPARTHI

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

Profile icon
DiegoCamacho3

@RYANTADIPARTHI
i fixed the thing a while ago but thanks

Profile icon
RYANTADIPARTHI

@DiegoCamacho3
oh, ok nvm.

Profile icon
Coder100

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

image

Profile icon
DiegoCamacho3

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

Profile icon
Coder100

cool, so what's not working?

@DiegoCamacho3