numL = [];
for count in range (6):
num = input("Enter Numbers ");
if int(num) <= -999:
print("Sentinel value was entered")
print(int(num) > sum(int(num))/ float(len(int(num))))
[a for a in your_list if a > sum(your_list) / len(your_list)]
如果你不熟悉列表的理解,这基本上是说:
for every element a in your_list, add a to a new list if it's greater than the sum of the list divided by its length (i.e. its mean). Return the new list.
您可以使用列表理解轻松完成以下任务:
如果你不熟悉列表的理解,这基本上是说:
例如,对于列表
[1, 2, 3, 4, 5, 6, 7, 8, 9]
,它返回[6, 7, 8, 9]
。你知道吗在Python3.4中,可以使用statistics.mean和list comp:
不确定if语句在做什么,但您可以在获得输入时创建一个if nums列表:
相关问题 更多 >
编程相关推荐