Question: Can someone please convert this C++ code to python? Thanks. The file includes the following data: 0.20 0.00 0.00 T 0.00 0.05 2.45 0.00 0.21
Can someone please convert this C++ code to python? Thanks.
The file includes the following data:
0.20
0.00
0.00
T
0.00
0.05
2.45
0.00
0.21
0.00
0.00
0.34
#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.00; i++; } for(int p=0; p<=i; p++) { sum = sum+myArray[p]; } int l=0; for(int k=1; k { if(myArray[k]<0.10) { l++; } else { cout< avg=avg+l; z=z+1; l=0; } } cout<<"Average = "< cout<<"Total rainfall: "<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
