[英]how to use while loop to determine the amount of numbers in a list that are greater the average
[英]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
我正在尝试使用python 3找出问题的第二部分,但似乎无法解决。 我拥有的代码的前半部分如下:
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")
将数字保存在列表中。 对列表进行排序,然后检查等于或大于平均数的数字。 然后,U可以轻松找到小于和大于平均数的数字计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.