fork download
  1. arr = [1.5, 2.3, 1.1, 0.9]
  2. count = 0
  3. indices = []
  4.  
  5. for i in range(len(arr) - 1):
  6. if arr[i] > arr[i + 1]:
  7. indices.append(i)
  8. count += 1
  9.  
  10. print(f"In the array {arr}, the indices {indices} correspond to elements {[arr[idx] for idx in indices]} which are greater than their right - hand neighbors.")
  11. print(f"In the array {arr}, the number of such elements (K) is {count}.")
Success #stdin #stdout 0.07s 14124KB
stdin
Standard input is empty
stdout
In the array [1.5, 2.3, 1.1, 0.9], the indices [1, 2] correspond to elements [2.3, 1.1] which are greater than their right - hand neighbors.
In the array [1.5, 2.3, 1.1, 0.9], the number of such elements (K) is 2.