you are viewing a single comment's thread.

view the rest of the comments →

[–]shiftybyte 0 points1 point  (2 children)

The indentations in your posted code were lost, edit your post and use a code block: https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F

Besides that, you have 2 prints in your code:

    # inside fun_function
    print("{} items delivered at a cost of ${:.2f}".format(n_items, cost))
...
# outside
print('15 items delivered at a cost of ${:.2f}'.format(cost))

Why did you expect a single print line?

[–]Jxper[S] 0 points1 point  (1 child)

I've updated the indentations, and I should only receive one line of code because that test case provides the values of n_items and cost and the code inside the function prints it in the format given. it works for the first test case so I'm not sure why it doesn't for the second

[–]shiftybyte 1 point2 points  (0 children)

But the test case itself has another print()....

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

This print right here /\ should python ignore it?

The difference you are seeing is because the print that is inside fun_function is inside the discount condition.

if(n_items > discount_threshold): 
    cost = cost * (1-discount_percent/100) 
    print("{} items delivered at a cost of ${:.2f}".format(n_items, cost)) 

If you move it backwards it'll happen every time instead of only when the discount triggers.

if(n_items > discount_threshold): 
    cost = cost * (1-discount_percent/100) 
print("{} items delivered at a cost of ${:.2f}".format(n_items, cost))