Help us understand the problem. What is going on with this article?

日章旗で円周率を求めてみた

More than 1 year has passed since last update.

Pythonを使って円周率を出すプログラムを作ってみました。
数学に興味を持ってもらうためのツールとしてPythonを活用しました。

pi.py
#平成も終わりそうなので日章旗で円周率を求めてみた
%matplotlib inline
#玉手箱3つ(matplotlib、random、math)を使う
import matplotlib.pyplot as plt
import random
import math

#dot(点)を0とする
dot = 0
#1万個点を打つ
for i in range(10000):
  #点のx座標は1~100
  x = random.randint(1, 100)
  #点のy座標は1~100
  y = random.randint(1, 100)
  #中心から点までの距離(三平方の定理)
  d = math.sqrt((x-50)**2 + (y-50)**2)
  #もしdが50以下なら
  if (d <= 50):
  #dotに1を足す
    cnt += 1
  #赤色で点を打つ
    plt.scatter(x, y, marker='.', c='r')
  #その他の場合
  else:
  #白色で点を打つ
    plt.scatter(x,y,marker='.', c='w')
plt.axis('equal')
plt.show()

#円周率を求める
p = dot / 10000
pi = p * 4
print(pi)

日章旗.png

takahashikaito94
ボードゲームを使ったプログラミング学習法を構想中です! like:将棋、囲碁、チェス、カタンetc・・・
https://note.mu/brett_spiel
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした