def main():
filename = input("Enter a file name: ")
with open(filename) as f:
data = [int(line) for line in f]
if len(data) > 2:
print('The smallest number in the file is: ', + min(data))
print('The largest number in the file is: ', "{:,}".format(+ max(data)))
print('The total sum of the number in the file is: ', "{:,}".format(sum(data)))
print('The average from the numbers in the file is: ', "{:,.2f}".format(sum(data)/len(data)))
elif len(data) == 1:
print ('There is only one number in your file to process.')
else:
print('There are no numbers in your file to process.')
f.close()
main()
Tags:
根据您的评论,我认为问题出在您的数据上,要解决这个问题,您可以使用以下方法:
请注意,这只解决了您得到的异常-我没有检查代码的其余部分并验证逻辑
相关问题 更多 >
编程相关推荐