Question: Rewrite the following C++ program in python. This is a program to estimate pi value by using Monte Carlo simulation. Use random numbers. Print your

Rewrite the following C++ program in python.

This is a program to estimate pi value by using Monte Carlo simulation.

Use random numbers.

Print your results with 6 digit precisions.

#include #include #include #include using namespace std; int main (){ int num = 0; int nummax = 10000; double x, y, est_pi, ratio; double hit =0; srand(time(0)); while(num < nummax){ y = double(rand())/double(RAND_MAX); x = double(rand())/double(RAND_MAX); cout << x << "," << y << endl; num++; if(pow(x,2) + pow(y,2) <= 1){ hit++;} } ratio = hit/nummax; est_pi = ratio * 4; cout<<"The estimated pi value is "<

}

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!