Just working my way through the python course, and wanted to take a break to play around with what I have so far. So creating a very basic text game and am stuck trying to re-use a variable on a later line.
In the first instance I want the variable char_name to be declared by the player, however I would like that raw_input stored so I can re-use the players name throughout.
Can I somehow tell python that the input is to be assigned to char_name permanently or do I need to create another variable and make it’s value = to the raw_input and if so how do I go about this?
P.S #This is my first attempt at making any sort of code so apologies if it’s horribly written, I realize that there will be more efficient ways to do this which I will learn in time.
Thanks in advance.
from time import sleep def TheGame(): print "What fool dares enter my dungeon!!?" char_name = raw_input("Enter your name: ") if len(char_name) > 0 and char_name.isalpha(): print "Well, well, well %s. This is no place for the weak." % (char_name) print "Do you truly believe a mortal creature like you will leave this dungeon?" ;sleep(2) else: print "YOU WILL GIVE ME YOUR NAME!!!" ;sleep(2) TheGame() brave = raw_input ("Well are you brave enough to begin %s?") % (char_name) TheGame()