Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- budget = float(input())
- product = input()
- counter = 0
- total = 0
- while product != "Stop":
- price = float(input())
- counter += 1
- if counter % 3 == 0:
- price /= 2
- total += price
- if budget < total:
- break
- product = input()
- if product == "Stop":
- print(f"You bought {counter} products for {total:.2f} leva.")
- else:
- print(f"You don't have enough money!")
- print(f"You need {total - budget:.2f} leva!")
- РЕШЕНИЕ С FOR:
- import sys
- budget = float(input())
- total = 0
- for i in range(1, sys.maxsize):
- product = input()
- if product == "Stop":
- print(f"You bought {i - 1} products for {total:.2f} leva.")
- break
- price = float(input())
- if i % 3 == 0:
- price /= 2
- total += price
- if budget < total:
- print(f"You don't have enough money!")
- print(f"You need {total - budget:.2f} leva!")
- break
- ИЛИ С FOR И ТЕРНАРЕН ОПЕРАТОР:
- import sys
- budget = float(input())
- total = 0
- for i in range(1, sys.maxsize):
- product = input()
- if product == "Stop":
- print(f"You bought {i - 1} products for {total:.2f} leva.")
- break
- total += float(input()) / (2 if i % 3 == 0 else 1)
- if budget < total:
- print(f"You don't have enough money!")
- print(f"You need {total - budget:.2f} leva!")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement