I am writing a text adventure game in which the user inputs information. I am having problems when I try to add the users name and accessory into the game. Basically I am having a problem implementing custom user input.
def welcome():
name()
accessory()
print(str(name) + """, you are a sleep in the quarters of the fine ship named ___. Starting to wake up you here your captain yelling at the crew. You think its best if you get up now. What is your response?""")
option = input("> ")
if option == "wake" or option == "Wake":
wake_up()
else:
welcome()
def wake_up():
print("""You are now awake and ready to start the day. You head down into your room puting on your """ + str(accessory) + """, seeing a backpack off to the
corner. As the software engineer it is your job to work on the electronics and maintain the ships systems. """)
option = input("> ")
if option == "west":
west()
elif option == "east":
east()
elif option == "south":
south()
elif option == "north":
north()
def take():
print("""You have collected a backpack which contains: a computer, a guide to grues, programming and sci-fi books and the gravity falls dvd set.""")
def west():
print("""You head west to find the lunchroom. Filled with all sorts of wonderful foods.""")
def north():
print()
def east():
print()
def south():
print()
def name():
name = input("What is your name: ")
def accessory():
accessory = input("What is your accessory: ")
welcome()
>Solution :
What you need to do here is to store the values that are entered in the functions.
To do this, you need to return the value of the variable to which you store the entered text in the functions.
def welcome():
name = ask_name()
accessory = ask_accessory()
print(f"Hello {name}. You have a nice {accessory}")
def ask_name():
n = input("What is your name?")
return n
def ask_accessory():
a = input("What is your accessory?")
return a
Read up on calling functions and returning values and start from there.