Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- target = int(input())
- cash = 0
- cash_counter = 0
- cart = 0
- cart_counter = 0
- counter = 0
- while target > 0:
- command = input()
- if command == "End":
- print("Failed to collect required money for charity.")
- break
- product_price = int(command)
- if counter % 2 == 0 and product_price > 100 or counter % 2 == 1 and product_price < 10:
- print("Error in transaction!")
- counter += 1
- continue
- elif counter % 2 == 0:
- cash += product_price
- cash_counter += 1
- else:
- cart += product_price
- cart_counter += 1
- print("Product sold!")
- counter += 1
- target -= product_price
- if target <= 0:
- print(f"Average CS: {cash / cash_counter if cash > 0 else 0:.2f}")
- print(f"Average CC: {cart / cart_counter if cart > 0 else 0:.2f}")
- break
- Решение с for:
- import sys
- target = int(input())
- cash = 0
- cash_counter = 0
- cart = 0
- cart_counter = 0
- for i in range(sys.maxsize):
- command = input()
- if command == "End":
- print("Failed to collect required money for charity.")
- break
- product_price = int(command)
- if i % 2 == 0 and product_price > 100 or i % 2 == 1 and product_price < 10:
- print("Error in transaction!")
- continue
- elif i % 2 == 0:
- cash += product_price
- cash_counter += 1
- else:
- cart += product_price
- cart_counter += 1
- print("Product sold!")
- target -= product_price
- if target <= 0:
- print(f"Average CS: {cash / cash_counter if cash > 0 else 0:.2f}")
- print(f"Average CC: {cart / cart_counter if cart > 0 else 0:.2f}")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement