+ 1

Kaleidoscopes

Where is my mistake? The solution I'm getting, when I get a input of 3 is wrong by 0.1 evertime: You sell souvenir kaleidoscopes at a gift shop, and if a customer buys more than one, they get a 10% discount on all of them! Given the total number of kaleidoscopes that a customer buys, let them know what their total will be. Tax is 7%. All of your kaleidoscopes cost the same amount, 5.00. Task: Take the number of kaleidoscopes that a customer buys and output their total cost including tax and any discounts. Input Format: An integer value that represents the number of kaleidoscopes that a customer orders. Output Format: A number that represents the total purchase price to two decimal places. Sample Input: 4 Sample Output: 19.26 my solution: num = int(input()) disc = 0.1 tax = 0.07 cost = 5 total = 0 if num > 1: total = num*cost+(num*cost*tax)-(disc*num*cost) else: total = num*cost+(num*cost*tax) print(round(total,2))

26th Mar 2022, 2:07 PM
David Lau
David Lau - avatar
9 Respostas
+ 2
#This way, is it not working..? num = int(input()) disc = 0.1 tax = 0.07 cost = 5 total = num * cost if num > 1: total += (total*tax) total -= disc*total else: total += (total*tax) print(round(total, 2))
27th Mar 2022, 11:55 AM
Jayakrishna 🇮🇳
+ 1
Discount should be applied on net total. ie total -= (total +tax)*disc you are applying only on cost hope it helps...
26th Mar 2022, 2:24 PM
Jayakrishna 🇮🇳
+ 1
But when I apply the discount on tax+cost, the result is also wrong.
26th Mar 2022, 11:34 PM
David Lau
David Lau - avatar
+ 1
It is working! I will need a few minutes to understand 😅
27th Mar 2022, 11:58 AM
David Lau
David Lau - avatar
+ 1
Ok, finally I've found the mistake in my way of thinking! Thank you a lot, Jayakrishna!
27th Mar 2022, 12:10 PM
David Lau
David Lau - avatar
+ 1
Arin can you explain what you mean? I said about only discount, not tax i think. And discount will deducted and tax will be added to total.
14th May 2023, 3:34 PM
Jayakrishna 🇮🇳
+ 1
Arin You can apply discount on total price combined with tax. ( total += total*0.07 ) =>then deduct discount Or You can apply tax on total price combined with discount as you are doing. (price-discount) * 0.07 Deduct discount total-=total*0.1 => then add tax to total. ( not you just applied on price) either way, you apply on net total price, not just on price. But OP did price*0.07 ( price is num*5). and discount is price*0.1) both original prices, but not on grant total price. so that's the mistake what i told. Hope it clears my intention there to you...
15th May 2023, 10:06 AM
Jayakrishna 🇮🇳
0
Jayakrishna 🇮🇳sorry for replying in this discussion thread 1 year later but discount applied on net total or tax applied on net total is the same as per my calculations
13th May 2023, 3:18 PM
Arin
Arin - avatar
0
# Jayakrishna 🇮🇳 qty = int(input()) price = qty*5.00 discount = price*0.1 tax = (price-discount)*0.07 if qty>1: total = price + tax - discount elif qty==1: discount = 0 total = price*1.07 print(round(total,2)) #here as you can see I have put discount over price and i have applied tax overall total price combined with discount
15th May 2023, 1:54 AM
Arin
Arin - avatar