Series31. Integers K, N and K sets of integers with N elements in each set are given. Find the number of sets containing the number 2. If there are no such sets, output 0.

Solution in Python 3:

import random

N = random.randrange(1,7)
K = random.randrange(1,7)

print("N = ",N)
print("K = ",K)
S = 0
for i in range(0,K):
flag = False
for j in range(0,N):
x = random.randrange(0,4)
print(x,end="; ")
if x == 2:
flag = True
if flag:
S += 1
print()

print()
print("Количество наборов, содержащих 2:",S)