从从键盘输入10个学生的成绩,返回低于平均分的人数,并将低于平均分的分数放在名为below的数值中。
Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘。demo:
str = raw_input("Enter your input: ");
print "Received input is : ", str
用一个 for 循环接收十次输入,然后存储到一个数组中。再用函数计算平均值,后遍历数组对比元素和平均值输出 below 的值。
students=eval(input('enter the scores:').split(' '))
average=students.sum()/len(students)
below=[]
for i in students:
if i <average:
below.append(i)
键盘输一个分数之后敲一下空格在输入下一个分数