+ 2

How can I simplify this code on python

Code Coach: Kaleidoscope Task description (for non-pro users) 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. =================================== My submission: x = float(input()) kaleidoscopes = 5 * x tax_cut = kaleidoscopes * (7/ 100) tax = kaleidoscopes + tax_cut discount = tax * (10/ 100) def total(x): if x <= 1: return kaleidoscopes + tax_cut else: if x > 1: return kaleidoscopes + tax_cut - discount print(round(total(x), 2))

3rd Feb 2021, 1:05 PM
Yeriel Vanderhost
Yeriel Vanderhost - avatar
2 Respuestas
+ 3
x = int(input()) If x > 1: total = x * 5 * 1.07 * 0.9 else: total = x * 5 * 1.07 print(round(total, 2)) If tax is considered after discount, it will true. Also you can write if-else statement in one line.
3rd Feb 2021, 1:56 PM
Михаил Иванов
Михаил Иванов - avatar
+ 3
x=int(input()) tax = x*5 + ×*5*0.07 Total = tax - tax*0.1 if ×>1 else tax print(round(Total, 2))
3rd Feb 2021, 3:55 PM
Hisham YUM 🇲🇦
Hisham YUM 🇲🇦 - avatar