上传PDF到wordpress网站,中国建设银行 官方网站,网站建设东北,动效做的好的网站在文本文件中#xff0c;有一个名称列表#xff0c;旁边有一个数字#xff0c;表示他们在本例中的分数。有没有办法计算出文本文件中所有数字的平均值。在
代码#xff1a;print(average calculator)
option input(option: )
option_class input…在文本文件中有一个名称列表旁边有一个数字表示他们在本例中的分数。有没有办法计算出文本文件中所有数字的平均值。在
代码print(average calculator)
option input(option: )
option_class input(class: )
one 1.txt
if option.lower() avg and option_class 1:
name input(name: )
with open(one) as f:
the_list [int(l.strip().split()[-1]) for l in f if name in l]
b sum(the_list)
length len(the_list)
avg float(b) / length if length else 0
print (name,Average is: , avg)
代码询问用户名称的部分这里它会找到文本文件中名称旁边的所有数字但是我正在尝试删除这一方面并允许代码识别文件中的所有数字。。。在
文本文件
^{pr2}$
从这些数字中[3,4,6]应算出平均值注意可以附加文本文件可以添加更多的名称和分数。在
蒂娅在