Advertisement
Spocoman

02. Report System

Dec 29th, 2021 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. target = int(input())
  2.  
  3. cash = 0
  4. cash_counter = 0
  5. cart = 0
  6. cart_counter = 0
  7. counter = 0
  8.  
  9. while target > 0:
  10.     command = input()
  11.     if command == "End":
  12.         print("Failed to collect required money for charity.")
  13.         break
  14.     product_price = int(command)
  15.     if counter % 2 == 0 and product_price > 100 or counter % 2 == 1 and product_price < 10:
  16.         print("Error in transaction!")
  17.         counter += 1
  18.         continue
  19.     elif counter % 2 == 0:
  20.         cash += product_price
  21.         cash_counter += 1
  22.     else:
  23.         cart += product_price
  24.         cart_counter += 1
  25.     print("Product sold!")
  26.  
  27.     counter += 1
  28.     target -= product_price
  29.     if target <= 0:
  30.         print(f"Average CS: {cash / cash_counter if cash > 0 else 0:.2f}")
  31.         print(f"Average CC: {cart / cart_counter if cart > 0 else 0:.2f}")
  32.         break
  33.  
  34.  
  35. Решение с for:
  36.  
  37. import sys
  38.  
  39. target = int(input())
  40.  
  41. cash = 0
  42. cash_counter = 0
  43. cart = 0
  44. cart_counter = 0
  45.  
  46. for i in range(sys.maxsize):
  47.     command = input()
  48.     if command == "End":
  49.         print("Failed to collect required money for charity.")
  50.         break
  51.     product_price = int(command)
  52.     if i % 2 == 0 and product_price > 100 or i % 2 == 1 and product_price < 10:
  53.         print("Error in transaction!")
  54.         continue
  55.     elif i % 2 == 0:
  56.         cash += product_price
  57.         cash_counter += 1
  58.     else:
  59.         cart += product_price
  60.         cart_counter += 1
  61.     print("Product sold!")
  62.  
  63.     target -= product_price
  64.     if target <= 0:
  65.         print(f"Average CS: {cash / cash_counter if cash > 0 else 0:.2f}")
  66.         print(f"Average CC: {cart / cart_counter if cart > 0 else 0:.2f}")
  67.         break
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement