简体   繁体   English

取平均值并再次通过列表。 计算大于平均值的数量和小于平均值的数量

[英]Take the average and go through the list again. Count the amount of numbers greater than the average and the amount of numbers less than the average

I'm trying to figure out the 2nd half of this question using python 3 but can't seem to figure it out. 我正在尝试使用python 3找出问题的第二部分,但似乎无法解决。 The first half of the code that I have is the following below... 我拥有的代码的前半部分如下:

A = [1,2,3,4] print(average(A)) 2.5 A = [1,2,3,4] print(平均值(A))2.5

num = int(input('How many numbers: '))
total_sum = 0
for n in range(num):
    numbers = float(input('Enter number : '))
    total_sum += numbers
avg = total_sum/num
print('Average of ', num, ' numbers is :', avg)

number = int(input("Enter number: "))
if number < 2.5:
    print("Your number is smaller than 2.5")
else:
    print("Your number is greater than 2.5")

Save the numbers in list. 将数字保存在列表中。 Sort the list and check the number which is equivalent to or greater than an average number. 对列表进行排序,然后检查等于或大于平均数的数字。 U can then easily find the count of numbers less than and greater than avarage number. 然后,U可以轻松找到小于和大于平均数的数字计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM