from random import randint
s = k = 0
mass = []
for i in range(10):
n = randint(0, 700)
mass.append(n)
if n < 50:
s += i
k += 1
print(mass)
print(s / k)
Объяснение:
import array
a = array.array ('i',[])
import random
_summ = _elem = 0
_len = int (input ("Lenght: "))
for l in range(_len):
a.append(random.randrange(0,700))
if a[l] < 50:
_summ+=a[l]
_elem+=1
print ("Summ: ", _summ)
if _elem != 0:
print("Average: ", _summ/_elem)
else:
print("Average: 0!")
print("Mass: ", a)
Результат работы:
Lenght: 20
Summ: 7
Average: 7.0
Mass: array('i', [266, 89, 7, 407, 506, 130, 630, 362, 419, 82, 639, 619, 695, 383, 685, 477, 368, 81, 62, 199])
Lenght: 5
Summ: 18
Average: 18.0
Mass: array('i', [486, 170, 18, 183, 307])
from random import randint
s = k = 0
mass = []
for i in range(10):
n = randint(0, 700)
mass.append(n)
if n < 50:
s += i
k += 1
print(mass)
print(s / k)
Объяснение:
import array
a = array.array ('i',[])
import random
_summ = _elem = 0
_len = int (input ("Lenght: "))
for l in range(_len):
a.append(random.randrange(0,700))
if a[l] < 50:
_summ+=a[l]
_elem+=1
print ("Summ: ", _summ)
if _elem != 0:
print("Average: ", _summ/_elem)
else:
print("Average: 0!")
print("Mass: ", a)
Результат работы:
Lenght: 20
Summ: 7
Average: 7.0
Mass: array('i', [266, 89, 7, 407, 506, 130, 630, 362, 419, 82, 639, 619, 695, 383, 685, 477, 368, 81, 62, 199])
Lenght: 5
Summ: 18
Average: 18.0
Mass: array('i', [486, 170, 18, 183, 307])