How do I repeat a choice in an Else/if format on Python?

623 views Asked by At

I am making a text-based game in Python, which I haven't touched in a while, for a class project. I want the game to use a name feature, and want the player to choose their name, so I put in a line of code that is supposed to allow them to repeat the line of code for entering their name. I am trying to use a loop for that, of course, but I don't know how to format it for an if/else statement. Here's the code I have:

def naming():
  print("A long, long time ago, there was a person who was born very ordinary, but would live to become very extraordinary.")
  time.sleep(3)
  name=input("Who are you? Give me your name.")
  choice=input("You said your name was ", name,", correct?")
  if choice in Yes:
    prologue():
  else:

I want to put the whole thing in a loop so that it repeats, (Which is why I haven't defined the "else" at the end) but I want the loop to break if the player says "yes" when prompted. Thanks for reading this far!

2

There are 2 answers

8
user7247147 On

you can do something like

while True:
    name=input("Who are you? Give me your name.")
    choice = input(f'You said your name was {name}, correct?')
    if 'yes' in choice.casefold():
        break
1
Rene707 On
while True:
    name=input("Who are you? Give me your name.")
    choice = input(f'You said your name was {name}, correct?')
    if 'yes' in choice.casefold():
        break

Credits to devdev_dev