Reputation: 13
I am trying to make a def function that uses ra_input, and the data is to be used outside the function. The function is to be called many times.
var1=""
var2=""
theresult=""
def getstuff():
theresult = raw_input("Enter your result")
print "Here is the result:"
print theresult
no result appears. Tried return, and tried return(), and tried return result, and tried return(result), anyone help?? Also why the box below unformatted when I type the question??
Upvotes: 1
Views: 189
Reputation: 563
Here are codes that should do the job.
def getstuff():
theresult = raw_input("Enter your result: ") return theresult
def main():
var1 = " " var2 = " "
theresult = getstuff()
print "Here is the result: "
print theresult
main()
Upvotes: 0
Reputation: 65861
The cleanest way would probably be:
def getstuff():
return raw_input("Enter your result")
theresult = getstuff()
print theresult
Another option would be to use global
, but I don't think it would be justified here.
Upvotes: 1