I am an absolute newbie when it comes to python and am learning by doing via my own text adventure game.
I have some code that enables the user to input their name:
# player name
def playerName():
name = ""
name = input("Before we begin, what is your name, warrior? ")
print("\n")
print("Welcome {}, now be on your way!".format(name))
print("\n")
This works as it is supposed to in the game. The player inputs their name and the game continues. However, I would like to be able to print the player's input later on in a different function and keep running the error message that name is undefined.. So I am trying to store this input as a global variable. I think that is the correct method, yes?
I have read up about storing functions as a global variable but these are always already specified by the programmer, i.e. name = sarah
.
How do I store the input so that I can print it later on? I thought print("string" + name)
would have been enough later on. But I have obviously misunderstood something.