Series38. An integer K and K sets of nonzero integers are given. Each set contains at least two elements, the sign of its completion is the number 0. For each set, perform the following action: if the elements of the set increase, then output 1; If the elements of the set decrease, then output -1; If the elements of the set do not increase and do not decrease, then output 0.

Solution in Python 3:

import random

K = random.randrange(1,9)
print("K = ",K)

N = 10
count_inc = 0
count_dec = 0
for i in range(0,K):
x_prev = random.randrange(1,N)
print(x_prev,end="; ")
x = random.randrange(1,N)
print(x,end="; ")

if x > x_prev:
flag_inc = True
else:
flag_inc = False
if x < x_prev:
flag_dec = True
else:
flag_dec = False

while True:
x_prev = x
x = random.randrange(0,N)
print(x,end="; ")
if x == 0:
break
if not (flag_inc and x > x_prev):
flag_inc = False
if not (flag_dec and x < x_prev):
flag_dec = False
print()
if flag_inc:
print("1. Increasing series")
elif flag_dec:
print("2. Decreasing series")
else:
print("0. Neither increases nor decreases")
print()