Series19. An integer N (> 1) and a set of N integers are given. Output those items in the set that are smaller than their left neighbor, and the number of K such elements.

Solution in Python 3:

import random

N = random.randrange(1,20)
print("N = ",N)

x = random.randrange(1,10)
print(x,end="; ")
x_prev = x
k = 0
for i in range(1,N):
x = random.randrange(1,10)
if x < x_prev:
k += 1
print("*{0}".format(x),end="; ")
else:
print(x,end="; ")
x_prev = x
print()
print("K = ",k)