from random import randint
a = [randint(0,100) for i in range(10)]
s50, sc50, k50, kc50 = 0, 0, 0, 0
for i in range(len(a)):
if a[i] < 50:
k50 += 1
s50 += a[i]
if a[i] >= 50:
kc50 += 1
sc50 += a[i]
print("Среднее арифметическое элементов, меньших 50:", s50 / k50)
print("Среднее арифметическое элементов, больших либо равно 50:", sc50 / kc50)
Ответ:
Python 3.8.какой-то
import statistics
import random
def main():
array = [random.randint(0, 100) for _ in range(10)]
avg_l = statistics.mean(filter(lambda p: p < 50, array))
avg_up = statistics.mean(filter(lambda p: p >= 50, array))
print(
f'average of condition "<50": {avg_l}, average of condition ">= 50": {avg_up}')
if __name__ == "__main__":
main()
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
from random import randint
a = [randint(0,100) for i in range(10)]
s50, sc50, k50, kc50 = 0, 0, 0, 0
for i in range(len(a)):
if a[i] < 50:
k50 += 1
s50 += a[i]
if a[i] >= 50:
kc50 += 1
sc50 += a[i]
print("Среднее арифметическое элементов, меньших 50:", s50 / k50)
print("Среднее арифметическое элементов, больших либо равно 50:", sc50 / kc50)
Ответ:
Python 3.8.какой-то
import statistics
import random
def main():
array = [random.randint(0, 100) for _ in range(10)]
avg_l = statistics.mean(filter(lambda p: p < 50, array))
avg_up = statistics.mean(filter(lambda p: p >= 50, array))
print(
f'average of condition "<50": {avg_l}, average of condition ">= 50": {avg_up}')
if __name__ == "__main__":
main()