Question: Can someone help me convert this C++ code to python? The rainfall_data.txt file contains the following information: 0.21 0.00 T 0.00 0.78 0.08 0.00 2.54

Can someone help me convert this C++ code to python? The rainfall_data.txt file contains the following information:

0.21 0.00 T 0.00 0.78 0.08 0.00 2.54 0.00 0.05 0.45

And the output should be the following:

Average = 2.33 days

Total rainfall: 4.12 inches

#include #include using namespace std; int main() { string inFileName="rainfall_data.txt"; fstream inFileStr(inFileName.c_str(), ios::in); float myArray[200]; string value; float avg; int i = 0; int z = 0; float sum = 0;

while(inFileStr >> value) { if(value!="T") myArray[i]=stof(value); else myArray[i] = 0.01; i++; } for(int p=0; p<=i; p++) { sum = sum+myArray[p]; } int l=0; for(int k=1; k<=i; k++) { if(myArray[k]<0.10) { l++; } else { avg=avg+l; z=z+1; l=0; } } cout<<"Average = "<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!