![](/img/trans.png)
[英]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.