这个问题可能听起来很愚蠢但我觉得很简单。
所以我有一个名为
的函数def print_location_summary(location_name):
and it dose its thing. and prints out a results.
我现在有另一个要求用户输入的功能:
def main():
"""Prompts for user to input a location name"""
location_name = input("Please enter location name:")
(NEED A CODE HERE)
main()
如何打印出第一个函数的结果作为第二个函数的结果
例如:
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()
但是那个clealy不起作用。请帮忙 :) 如果您需要更多信息,请告诉我。
答案 0 :(得分:1)
我不是100%确定我理解你的问题。但是没有打印的功能,我会让函数返回您想要打印的信息。即
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()
答案 1 :(得分:0)
对不起伙计们。这是一个愚蠢的问题。 这确实有效。
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()