Python Forum
Please help with code below!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help with code below!
#1
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
Reply
#2
Yeah I know, that's all the code in the right format.
Reply
#3
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.
Reply
#4
(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 :))
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020