Spocoman

05. Salary

Dec 24th, 2021 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. num = int(input())
  2. salary = int(input())
  3.  
  4. for i in range(num):
  5.     apps = input()
  6.     if apps == 'Facebook':
  7.         salary -= 150
  8.     elif apps == 'Instagram':
  9.         salary -= 100
  10.     elif apps == 'Reddit':
  11.         salary -= 50
  12.     if salary <= 0:
  13.         print('You have lost your salary.')
  14.         break
  15.        
  16. if salary > 0:
  17.     print(salary)
  18.  
  19. Решение с тернарен оператор:
  20.  
  21. num = int(input())
  22. salary = int(input())
  23.  
  24. for i in range(num or salary <= 0):
  25.     apps = input()
  26.     salary -= 150 if apps == "Facebook" else 100 if apps == "Instagram" else 50 if apps == "Reddit" else 0
  27.  
  28. print(salary if salary > 0 else "You have lost your salary.")
  29.  
  30.  
  31.  Решение с while и тернарен оператор:
  32.  
  33. num = int(input())
  34. salary = int(input())
  35.  
  36. while num != 0 and salary > 0:
  37.     apps = input()
  38.     salary -= 150 if apps == "Facebook" else 100 if apps == "Instagram" else 50 if apps == "Reddit" else 0
  39.     num -= 1
  40.  
  41. print(salary if salary > 0 else "You have lost your salary.")
  42.  
Add Comment
Please, Sign In to add comment