Albert
Albert

Reputation: 13

how to print results of function as the result of a input function?

The question might sound stupid but i think its pretty simple.

so i have a function called

def print_location_summary(location_name):
and it dose its thing. and prints out a results.

i now have another function that ask user of input:

def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")  

(NEED A CODE HERE)

main()  

how do i print out the results of the first function as the results of second function

for example:

def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")  
print(def print_location_summary(location_name))

main() 

but that clealy won't work. please help :) if you need more information please let me know.

Upvotes: 0

Views: 2257

Answers (2)

gigabyte
gigabyte

Reputation: 63

I'm not 100% sure I understand your question. But instead of having a function that prints I would have the function just return the information you want to print. i.e

def get_location_summary(location_name):
    output = "This is my output stored in a variable. My location is: " + location_name
    """ return the output to the caller """
    return output

def main():
    """Prompts for user input to a location name"""
    location_name = input('Please enter a location name: ')
    """print below calls the function which returns the value that was stored in the output variable inside get_location_summary. This value is then printed"""
    print(get_location_summary(location_name))

if __name__ == "__main__":
    main()

Upvotes: 1

Albert
Albert

Reputation: 13

Sorry guys. it was a stupid question. this actually works.

def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")    
print ("")
print (print_sorted_stock_summary(location_name))

main()

Upvotes: 0

Related Questions