How can I re-use user response (user input)

Hello, I decided to make another little game to implement my new knowledge in python. Problem is, I would like to be able to prompt the user for input (to ask for and reuse their name) and save their response to a variable so i can use it in later dialogue or something else. Am i able to just use… name = input("Please enter your name: ") …and then later on print something with their name in it…Are you able to just call the variable ‘name’ and put the name in the dialogue by print(“Hey " + name + " you won the game!”) or would that just prompt them to input their name again?

3 Likes

No, it would work, firstly it would get the input after that it saves it to a variable in this example name.
So after it did this it will work as a normal variable that a string was set to it.
It will only ask for user input once again if you re-define it.
for example:

name = input("Please enter your name: ") #i enter Ray
print("Your name is: " + name) #prints Your name is: Ray
name = input("What's your name again? ") //i enter Michael
print("Your name again is: " + name) #prints Your name again is: Michael

Hope this helps :grinning:

3 Likes

Fantastic!! Thank you very much!

3 Likes