How python represents pi

Updated on amusement 2024-03-18
3 answers
  1. Anonymous users2024-02-06

    python representationPiMethod:

    Use the "import" statement to import the math package. "The function can get pi, then you can use the function to represent pi."

    The following is an example: The following is the result:

  2. Anonymous users2024-02-05

    There are two methods for calculating pi, namely the mathematical formula method and the Monte Carlo method in engineering.

    1.Formula method.

    **:Running Effect:

    Note: Because the upper limit of k in the formula is positive infinity, here for the sake of simple calculation, take k=10000.

    If you increase the k value, you will find that the value of pi is more accurate, at the cost of a longer running time. When I set n to 10000000, the computer fan started whirring for a long time.

    2.Monte Carlo method.

    The core idea: the value of pi ( ) is indirectly equal to the ratio of the number of points falling into the circle to the total number of points in the square.

    To make it easier to calculate, let's first calculate the PI value of 1 4 circles, and then multiply by 4 to get the PI value of the whole circle.

    1 4 Circular dot simulation.

    ** As follows: Notes:

    dots is the total number of random dots scattered within a 1 4 square.

    Hits are used to record the number of points that fall within 1 4 circles.

    The random() function is used to generate a random number between 0 and 1, which is a unit circle, exactly If you don't set the seed, it will automatically be seeded according to the current time of the operating system (accurate to milliseconds). Therefore, the randomly generated 1000*1000 points must be different, and there will be no overlap of points.

    pow(x**2+y**2, which is used to calculate the Euclidean distance from the random point (x,y) to the center of the circle o(0,0). Namely.

    When the distance is 1, it means that the random point is within 1 4 circles, and the Hits variable is increased by 1.

    The result is as follows:

    It can be seen that the value of pi is not accurate enough, and this problem can be solved by increasing the number of dots.

  3. Anonymous users2024-02-04

    3. After that, a new page will appear - 3 ways to retrieve the QQ password.

    4. Below, let's take a look at the first way to retrieve the QQ password: verify the password problem. Correctly answer the 3 security questions, click "OK" - enter the new password reset and confirm, confirm the submission - QQ password modification is successful.

    5. Then let's look at the second way to retrieve the QQ password: send a text message on your mobile phone. Use the password mobile phone number SMS "GM your QQ account new password" format to send to the port number (China Unicom Telecom user).

    Note: Sending SMS will be charged for the Yanqi fee: yuan).

    6. After that, let's look at the third way to retrieve QQ password: account appeal. If the password verification problem is incorrect, or "the password phone is not bound", then you can retrieve the QQ password through an account appeal.

    Enter the QQ account and verification code, click "Confirm and agree to the following agreement" -- verify the contact email phone -- fill in the historical information to verify the identity -- notify your friends to complete the assistance to retrieve the QQ password -- check the email text message after four hours, set a new QQ password, and protect the password.

    QQ, that is, Tencent QQ, is composed of numbers, and the QQ number is randomly selected by the system when the user registers. The shortest QQ is 5 digits, and the length has reached 10 digits. It is an Internet-based instant messaging software developed by Shenzhen Tencent Computer System.

Related questions
12 answers2024-03-18

Draw a perfect circle, measure the circumference, diameter. >>>More

7 answers2024-03-18

A temple on the top of the mountain and a pot of wine (, two slip houses (265), three houses to eat wine (35897), wine to kill (932)! Can't Kill (384), Happy and Happy (6264)! Fan fan scraping (338), fan ear eating wine (3279). >>>More

3 answers2024-03-18

Zu Chongzhi (429-500 AD) was a native of Laiyuan County, Hebei Province during the Northern and Southern Dynasties of China He read many books on astronomy and mathematics since he was a child, and he was diligent and studious, and practiced hard, which finally made him an outstanding mathematician and astronomer in ancient China >>>More

15 answers2024-03-18

Scientists have found that the circle is the simplest and most perfect shape in the world. Therefore, in ancient times, the degree of knowledge and understanding of circles can be used as a yardstick to measure the mathematical level of a nation. >>>More

5 answers2024-03-18

Zu Chongzhi (429-500 AD) was a native of Laiyuan County, Hebei Province during the Northern and Southern Dynasties of China He read many books on astronomy and mathematics since he was a child, and he was diligent and studious, and practiced hard, which finally made him an outstanding mathematician and astronomer in ancient China >>>More