Advertisement
webbersof

Computer Store

Feb 15th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. total_price_no_tax = 0
  2. total_price_with_tax = 0
  3.  
  4. #  Тук ти я изнесох променливата taxes за да може да не дава грешка в края кода
  5. taxes = 0
  6.  
  7. while True:
  8.     prices = input()
  9.  
  10.     #  по условие са ти казали ако е special да вадиш 10%, а ти не го правеш, сега съм ти го написал правилно.
  11.     if prices == "special":
  12.         total_price_with_tax -= total_price_with_tax * 0.10
  13.         break
  14.  
  15.     elif prices == "regular":
  16.         break
  17.  
  18.     #  По условие не правиш тази проверка за това дали цента е по-малка от 0-ла и
  19.     #  ако е трябва да спреш условията надолу да не се изпълнят, за това ползвам continue
  20.     if float(prices) < 0:
  21.         print("Invalid price!")
  22.         continue
  23.  
  24.     total_price_no_tax += float(prices)
  25.     # Това е начина който ти използваш за 20те процента
  26.     # total_price_with_tax = (total_price_no_tax * 120) / 100
  27.  
  28.     #  Това е моя начин да го намеря
  29.     total_price_with_tax = (total_price_no_tax + (total_price_no_tax * 0.20))
  30.     taxes = total_price_with_tax - total_price_no_tax
  31.  
  32. #  Това е друга проверка която не извършваш в кода ти, а именно - дали крайната сума е по-голяма от 0-ла
  33. if total_price_with_tax != 0:
  34.     print("Congratulations you've just bought a new computer!")
  35.     print(f"Price without taxes: {total_price_no_tax:.2f}$")
  36.     print(f"Taxes: {taxes:.2f}$")
  37.     print("-----------")
  38.     print(f"Total price: {total_price_with_tax:.2f}$")
  39. else:
  40.     print("Invalid order!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement