I currently have a variable in one of my functions. A separate function after it utilizes the variable but cannot seem to use it and creates a syntax error. Is it possible to store a variable inside of a function?
Can I store a variable inside of a function?
Collapse
X
-
Tags: None
-
My code is a bit long so I'll sum it up here.
it results in a syntax error when i try to pull the value of the variable from the previous function.Code:def weapon(): weapon = raw_input("What weapon would you like?") def forest_troll(): return "You stroke out with your " + weapon + "." weapon(x) forest_troll()
Also, the spaces/indents didnt show up sorryComment
-
Return the weapon selection in function weapon() similar to:
Your code will indent properly by using code tags.Code:>>> def weapon(): ... return raw_input("What weapon would you like?") ... >>> def forest_troll(w): ... return "You stroke out with your " + w + "." ... >>> forest_troll(weapon()) 'You stroke out with your Knife.' >>>Comment
-
I tried your suggested code but it didn't work for me?Return the weapon selection in function weapon() similar to:
Your code will indent properly by using code tags.Code:>>> def weapon(): ... return raw_input("What weapon would you like?") ... >>> def forest_troll(w): ... return "You stroke out with your " + w + "." ... >>> forest_troll(weapon()) 'You stroke out with your Knife.' >>>Comment
Comment