Advertisement
Spocoman

09. Hello, France

Jan 23rd, 2022 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. Решение с тернарен оператор:
  2.  
  3. products = input().split('|')
  4. budget = float(input())
  5.  
  6. cash = budget
  7. profit = []
  8.  
  9. for p in products:
  10.     p = p.split('->')
  11.     product = p[0]
  12.     price = float(p[1])
  13.     max_price = 50.00 if product == 'Clothes' else 35.00 if product == 'Shoes' else 20.50
  14.     if price <= cash and max_price >= price:
  15.         profit.append(price * 1.4)
  16.         cash -= price
  17.  
  18. for price in profit:
  19.     print(f'{price:.2f} ', end='')
  20.  
  21. print(f'\nProfit: {sum(profit) - budget + cash:.2f}')
  22. print('Hello, France!' if sum(profit) + cash >= 150 else 'Not enough money.')
  23.  
  24. Решение с речник и тернарен оператор:
  25.  
  26. products = input().split('|')
  27. budget = float(input())
  28.  
  29. cash = budget
  30. profit = []
  31. max_price = {'Clothes': 50.00, 'Shoes': 35.00, 'Accessories': 20.50}
  32.  
  33. for p in products:
  34.     p = p.split('->')
  35.     product = p[0]
  36.     price = float(p[1])
  37.     if price <= cash and max_price[product] >= price:
  38.         profit.append(price * 1.4)
  39.         cash -= price
  40.  
  41. for price in profit:
  42.     print(f'{price:.2f} ', end='')
  43.  
  44. print(f'\nProfit: {sum(profit) - budget + cash:.2f}')
  45. print('Hello, France!' if sum(profit) + cash >= 150 else 'Not enough money.')
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement