I'm trying to figure out how to extract data from a `.txt` file where I need to filter based on certain keywords, then convert those values to floats. My goal is to calculate a total sum as **(number of data points / total sum of values)**, but the twist is that the problem specifically prohibits the use of the `sum()` function. Am I missing something? I'd love to hear your suggestions on how to tackle this! If you want, I can also share a possible approach for solving this. Let me know your thoughts!
3 Answers
Are you sure you can't use other methods for accumulating values? If you can leverage lists or even a simple loop, you should get the right result without `sum()`. Just break down your problem, it can be done!
You could just use a for loop to add up the values manually. Read through the file, filter for your keywords, convert the numbers to floats, and keep a running total. Then you can divide by the count of those numbers to get your final result!
Is this for a homework assignment? If so, I get why you're avoiding `sum()`, but don't worry, there are plenty of ways to get the sum using loops. Just iterate through the data, and filter while you go!
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String