Python Forum

Full Version: Please help with code below!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from time import sleep
print("Welcome to my first game")
char_name = ""
def choosingname(name):
    name = input("What is your charactar's name?: ")
    print(name)
    YorN()
def YorN():
    correctornot = input("Enter Y for yes if name is correct, enter N for no if name is not correct: ")
    if correctornot == "Y":
      print("You have your character's name!")
    elif correctornot == "N":
      print("Let's input the name again")
      choosingname()
    else:
      print("Invalid, neither Y or N was entered.")
      YorN()
choosingname(char_name)
print("CityBuilder: The Game. Is now running.")
sleep(1)
print("Hello %s, what's your city going to be called?" % char_name)
(Out of the code now: The code on the last line never prints the user's name why is that?)
Please help Huh
Yeah I know, that's all the code in the right format.
You should not be looping using recursion for a problem like this. It isn't what recursion is for.

Rewrite your program to loop with a while loop and I think you will see the issue.
(Jan-21-2018, 06:14 AM)Mekire Wrote: [ -> ]You should not be looping using recursion for a problem like this. It isn't what recursion is for. Rewrite your program to loop with a while loop and I think you will see the issue.
Thanks, I have tried a while loop but I shall try again (I'm new to python :))