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)
我在尝试使用排序功能时遇到问题我尝试过打印排序(年龄) 打印ages.sort()但等等,但似乎没有任何工作。
答案 0 :(得分:0)
您应该使用print(sorted(iterable))
代替print(sort(iterable))
来对可迭代进行排序。
答案 1 :(得分:0)
sort
实际上对列表进行了排序。这意味着,如果您print ages.sort()
None
,您将获得ages.sort(); print ages;
。相反,你可以做{{1}}