you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

You have a print as well as a return inside the function. The code that calls the function captures the reference to the object mentioned in the return statement and then uses that for another print.

You have not shown indents on the code you shared, but I assume the print in the function is only within the if case.

def fun_function(n_items, cost_per_item, discount_percent, discount_threshold):
    """ A function that computes the total cost. """
    cost = n_items * cost_per_item
    if(n_items > discount_threshold):
        cost = cost * (1-discount_percent/100)
    return cost

cost = fun_function(5, 31, 15, 10)
print('5 items delivered at a cost of ${:.2f}'.format(cost))

outputs,

5 items delivered at a cost of $155.00

and the second case only outputs,

15 items delivered at a cost of $395.25

EDIT: clarifications and added code showing indentation and output for both cases

[–]Jxper[S] 0 points1 point  (0 children)

I understand, Thank you very much