This code takes in input through raw_input()
in the user_input()
function, and then uses return
to return it. In our print_input()
function, we take in the input. In our main()
function, we assign the return value from user_input()
to name
, and then pass it into print_input()
.
def user_input():
name = raw_input("Please enter name input:\n> "
return name
def print_input(name):
print "Hello", name
def main():
name = user_input()
print_input(name)
if __name__ =="__main__":
main()
Edit
main.py
:
def user_input():
name = raw_input("Please enter name input:\n> "
return name
def print_input(name):
print "Hello", name
def main():
name = user_input()
print_input(name)
To call a function from here do the following:
>>> from main import user_input, print_input
>>>
>>> print_input(user_input())
Please enter name input:
> aj8uppal
Hello aj8uppal
>>>