Advertisement
go6odn28

computer_store

Feb 18th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.31 KB | None | 0 0
  1. def is_price_positive_number(tax_):
  2.     return tax_ >= 0
  3.  
  4.  
  5. def increase_taxes_with_twenty_percent(prices_without_taxes_, prices_with_taxes_):
  6.     prices_with_taxes_ = [price * 1.20 for price in prices_without_taxes_]
  7.     return prices_with_taxes_
  8.  
  9.  
  10. def take_ten_percent_of_discount(total_sum_, prices_with_taxes_):
  11.     total_sum_ = total_sum_ * 0.9
  12.     return total_sum_
  13.  
  14.  
  15. def take_taxes(taxes_, prices_without_taxes_, prices_with_taxes_):
  16.     taxes_ = sum(prices_with_taxes_) - sum(prices_without_taxes_)
  17.     return taxes_
  18.  
  19.  
  20. def print_result(total_price_without_taxes_, taxes_, total_sum_):
  21.     return print("Congratulations you've just bought a new computer!\n"
  22.                  f"Price without taxes: {total_price_without_taxes_:.2f}$\n"
  23.                  f"Taxes: {taxes_:.2f}$\n"
  24.                  "-----------\n"
  25.                  f"Total price: {total_sum_:.2f}$")
  26.  
  27.  
  28. def computer_store():
  29.     prices_without_taxes = []
  30.     prices_with_taxes = []
  31.     taxes = 0
  32.     type_of_customer = ""
  33.  
  34.     while True:
  35.         command = input()
  36.         if command == "special":
  37.             type_of_customer = "special"
  38.             break
  39.         elif command == "regular":
  40.             type_of_customer = "regular"
  41.             break
  42.         current_tax = float(command)
  43.  
  44.         if not is_price_positive_number(current_tax):
  45.             print("Invalid price!")
  46.             continue
  47.  
  48.         prices_without_taxes.append(current_tax)
  49.  
  50.     if prices_without_taxes:
  51.         total_price_without_taxes = sum(prices_without_taxes)
  52.         prices_with_taxes = increase_taxes_with_twenty_percent(prices_without_taxes, prices_with_taxes)
  53.         taxes = take_taxes(taxes, prices_without_taxes, prices_with_taxes)
  54.         total_sum = sum(prices_with_taxes)
  55.         if type_of_customer == "special":
  56.             total_sum = take_ten_percent_of_discount(total_sum, prices_with_taxes)
  57.  
  58.         print_result(total_price_without_taxes, taxes, total_sum)
  59.  
  60.     else:
  61.         print("Invalid order!")
  62.  
  63.  
  64. computer_store()
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. ##########################################################################################
  73.  
  74.  
  75. # price_without_task = 0
  76. # while True:
  77. #     command = input()
  78. #
  79. #     if command == 'special' or command == 'regular':
  80. #         break
  81. #
  82. #     price = float(command)
  83. #     if price < 0:
  84. #         print('Invalid price!')
  85. #         continue
  86. #
  87. #     price_without_task += price
  88. #
  89. # taxes = price_without_task * 0.2
  90. # final_price = price_without_task + taxes
  91. #
  92. # if command == 'special':
  93. #     if price_without_task > 0:
  94. #         discount = final_price * 0.1
  95. #         final_price = final_price - discount
  96. #         print(f"Congratulations you've just bought a new computer!\n"
  97. #               f"Price without taxes: {price_without_task:.2f}$\n"
  98. #               f"Taxes: {taxes:.2f}$\n"
  99. #               f"-----------\n"
  100. #               f"Total price: {final_price:.2f}$")
  101. #     else:
  102. #         print('Invalid order!')
  103. #
  104. # elif command == 'regular':
  105. #     if price_without_task > 0:
  106. #         print(f"Congratulations you've just bought a new computer!\n"
  107. #               f"Price without taxes: {price_without_task:.2f}$\n"
  108. #               f"Taxes: {taxes:.2f}$\n"
  109. #               f"-----------\n"
  110. #               f"Total price: {final_price:.2f}$")
  111. #     else:
  112. #         print('Invalid order!')
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement