+ 1

How can I fix that? (Python | code challenge)

Hello, I want to solve a code challenge Kaleidoscopes, but in test case #2 when input = 3, it outputs 14.445 instead of 14.45 (tax = 7%, if customer buys more than 1 kaleidoscope he gets 10% discount). Here's the code: kaleidoscopes = int(input()) kaleidoscope_cost = 5.00 if kaleidoscopes > 1: total = kaleidoscopes * kaleidoscope_cost total_discount = total - (total / 10) total_price = total_discount + (total_discount / 100) * 7 print(total_price) elif kaleidoscopes <= 1: total = 5.00 + (5 / 100) * 7 print(total) Is there a way to fix it, round the decimals or something? Very grateful for any form of help.

21st Aug 2023, 9:25 AM
Creepereq7
Creepereq7 - avatar
2 odpowiedzi
+ 5
print(round(total_price,2)) #rounding to 2 decimal places.
21st Aug 2023, 9:52 AM
Jayakrishna 🇮🇳
+ 2
Use the round(number,decimal) function, where [number] is the number you want to round up, and [decimal] the number of decimal places you want to round up. print(round(total,2))
21st Aug 2023, 10:46 AM
Dragon RB
Dragon RB - avatar