0
howManyNames = (float(input("Enter how many student names do you want to enter? ")))
studentNames = []
ages = []
averageAge = 0
counter = 0

while (counter < int(howManyNames)):
    studentNames.append(input("Enter student names. "))
    ages.append(float(input("Enter that persons age. ")))
    counter += 1
    averageAge = sum(ages) / float(howManyNames)
print ("Your average age is ", averageAge, "!")

for age in ages:
   if age < int(averageAge):
      print ("Your age is below the average age.", age)
   else:
      print ("Your age is above the average age.", age)

我在尝试使用我尝试过的排序功能时遇到问题 print sort(ages) printages.sort() 但是等等,但似乎没有任何效果。

4

2 回答 2

0

sort实际上对列表进行了排序。这意味着如果你这样做了,print ages.sort()你会得到None. 相反,你可以这样做,ages.sort(); print ages;

于 2013-11-15T01:42:00.377 回答
0

You should use print(sorted(iterable)) instead of print(sort(iterable)) to sort an iterable.

于 2013-11-15T01:41:17.140 回答