简体   繁体   English

如何将功能结果打印为输入功能的结果?

[英]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. 请帮助:)如果您需要更多信息,请告诉我。

I'm not 100% sure I understand your question. 我不确定100%知道您的问题。 But instead of having a function that prints I would have the function just return the information you want to print. 但是,除了具有要打印的功能外,我还可以让该功能返回您要打印的信息。 ie

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()

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:在函数本身中输出解析函数的结果,还是让函数返回结果并将其打印为外部调用函数? - Python: Print results of a parsing function in the function itself, or have the function return the result and print it an external calling function? 打印功能不打印结果 - Print function not printing results 如何运行 python function 并在 Python 中打印结果 - How to run a python function and print results in Python 如何将函数中的所有打印结果放入变量中? - How to put all print result in a function into a variable? 如何获得一个功能来从单独的功能打印结果,但是单独的功能不能打印结果。 - How to get a function to print the result from a separate function, but the separate function not print a result. 如何在while循环中保存来自输入()function的多个结果,而不是仅在Python中的最后一个结果? - How do i save multiple results from a input() function in a while loop, not the last result only in Python? 打印功能输入到int - Print function input into int 如何将输入语句放入打印 function 中? - How to put input statement inside a print function? 不要打印函数的结果 - don't print results of a function 如何在另一个函数的函数中打印嵌套输入 - How do I print a nested input in a function in another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM