Advertisement
Spocoman

Tourist Shop

Feb 17th, 2022 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. budget = float(input())
  2. product = input()
  3. counter = 0
  4. total = 0
  5.  
  6. while product != "Stop":
  7.     price = float(input())
  8.     counter += 1
  9.     if counter % 3 == 0:
  10.         price /= 2
  11.  
  12.     total += price
  13.  
  14.     if budget < total:
  15.         break
  16.  
  17.     product = input()
  18.  
  19. if product == "Stop":
  20.     print(f"You bought {counter} products for {total:.2f} leva.")
  21. else:
  22.     print(f"You don't have enough money!")
  23.     print(f"You need {total - budget:.2f} leva!")
  24.  
  25.  
  26. РЕШЕНИЕ С FOR:
  27.  
  28. import sys
  29.  
  30. budget = float(input())
  31. total = 0
  32.  
  33. for i in range(1, sys.maxsize):
  34.     product = input()
  35.     if product == "Stop":
  36.         print(f"You bought {i - 1} products for {total:.2f} leva.")
  37.         break
  38.  
  39.     price = float(input())
  40.  
  41.     if i % 3 == 0:
  42.         price /= 2
  43.  
  44.     total += price
  45.  
  46.     if budget < total:
  47.         print(f"You don't have enough money!")
  48.         print(f"You need {total - budget:.2f} leva!")
  49.         break
  50.  
  51.  
  52. ИЛИ С FOR И ТЕРНАРЕН ОПЕРАТОР:
  53.  
  54. import sys
  55.  
  56. budget = float(input())
  57. total = 0
  58.  
  59. for i in range(1, sys.maxsize):
  60.     product = input()
  61.     if product == "Stop":
  62.         print(f"You bought {i - 1} products for {total:.2f} leva.")
  63.         break
  64.  
  65.     total += float(input()) / (2 if i % 3 == 0 else 1)
  66.  
  67.     if budget < total:
  68.         print(f"You don't have enough money!")
  69.         print(f"You need {total - budget:.2f} leva!")
  70.         break
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement