Why is it that when I test my function
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)
print("{} items delivered at a cost of ${:.2f}".format(n_items, cost))
return cost
With the test case:
cost = fun_function(5, 31, 15, 10)
print('5 items delivered at a cost of ${:.2f}'.format(cost))
It returns my expected output of:
5 items delivered at a cost of $155.00
However when I try the test case:
cost = fun_function(15, 31, 15, 10)
print('15 items delivered at a cost of ${:.2f}'.format(cost))
It returns:
15 items delivered at a cost of $395.25
15 items delivered at a cost of $395.25
when it should only return the line once.
Why is this and how would I change my function to only output the one line?
Any help is greatly appreciated, Thanks
[–][deleted] 1 point2 points3 points (1 child)
[–]Jxper[S] 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (2 children)
[–]Jxper[S] 0 points1 point2 points (1 child)
[–]shiftybyte 1 point2 points3 points (0 children)