The answer provided by BedirYilmaz is correct and should be preferred. However, those more familiar with programming in Python could for some reason want to use functions the way you thought they worked. The function could be called, and then the name of the function could be used to get the return value as a string. If this is being done in a single-threaded program, the following example class ReturnWrapper should be sufficient for use as a function decorator:
class ReturnWrapper:
def __init__(self, function):
self.__function = function
self.__value = function
def __repr__(self):
return repr(self.__value)
def __str__(self):
return str(self.__value)
def __call__(self, *args, **kwargs):
self.__value = self.__function(*args, **kwargs)
return self.__value
def main():
meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())
solve(meal_cost, tip_percent, tax_percent)
print(solve)
@ReturnWrapper
def solve(meal_cost, tip_percent, tax_percent):
tip = meal_cost * (tip_percent / 100)
tax = meal_cost * (tax_percent / 100)
total_cost = round(meal_cost + tip + tax)
return total_cost
if __name__ == '__main__':
main()
If the actual return value needed to be retrieved after running the function, a value property would be very helpful on the class. Since it is rather simple to implement, it is left as an exercise for the reader to complete.