Ask coding questions

← Back to all posts
Please help me figure out how to do this.
ArtemPionov (8)

Problem

I'm currently programming a text-based game on python
and my struggle is:
I'm coding a game and I code different parts of the game use def and I want to ask for a user to input their character's name and then ask a question if they are sure and based on that do an if, else statement.

The code:

yes = ["Y", "y", "Yes", "yes"]
no = ["N", "n", "No", "no"]

def main_character():
  main_character = print(input("What's your character's name?"))
main_character = input(">>> "("Are you sure?"))
if main_character in yes:
  intro()
else main_character in no:
  main_character()

I want the code to set in the def main_character and I want the code to a user for the name are ask a question if the user is sure with the name and then do an if statement that gets input from the question and I have assigned variable "yes" and and "no" and if input from the question falls in the yes variable then continue to intro() which is beginning of the game and if the answer from the question falls into no variable then go back to the naming of the character.
Please help me! Thank you!

Answered by a5rocks (732) [earned 5 cycles]
View Answer
Commentshotnewtop
a5rocks (732)

Use elif instead of else. else is a blanket statement, it doesn't check a condition, while elif does.

LD1 (33)

Yes to what the last comment said. else is for if none of the above if statements are true. elif is for if none of the above if statements are true AND the following is true