In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how python reads the file and calculates the average value". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to read the file and calculate the average value of python" can help you solve the problem.
The specific steps are as follows:
1. First, open python and create a new python project
After the 2.python project is created, use the open () function in the project to open a file and create a file object
File = open ('test.txt', 'r')
3. After the file object is created, use the read () method to get the contents of the file
Res = file.read ()
4. After getting the contents of the file, iterate through the for loop to get the total number and number of files
For line in infile:
Amount = float (line)
Total + = amount
Length = length + 1
5. Finally, after the total number and number of files are obtained, the average value can be obtained by dividing the two numbers.
Average = total / length
Print (average)
That's all for "how python reads files and calculates averages". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.