I have a simple question about functions in python.
I would want to change a pre-declared variable inside a function, return it and view/change the information afterwards.
------------------------
HERE IS A SIMPLE EXAMPLE
------------------------
variable = 3 def function(variable): variable += 3 return variable print variable
-----------------------
WHAT I WANNA USE IT FOR
-----------------------
chosen_weapon = ''
def getWeapon(chosen_weapon):
chosen_weapon = raw_input ('Choose you weapon < Gun, knife>')
if chosen_weapon.startswith('g'):
chosen_weapon = 'gun'
elif chose_weapon.startswith('k'):
chosen_weapon = 'knife'
return chosen_weapon
if chosen_weapon == 'gun':
print 'You have chosen a gun. Ammo = 6'
elif chosen_weapon == 'knife':
print 'You have chosen a knife as your weapon.'
_________________________
So this is an example: what I want to use it for.
Does anybody have an idea? I want to take that information from the function. Actually the goal of the function is to give chosen_weapon a piece of information from which I can benefit later.
ARE THERE ANY OTHER WAYS OF DOING WHAT I NEED?
Thankyou in advance,
Wolfi


Sign In
Create Account

Back to top









