簡體   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

我正在嘗試使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM