math.pi
import math print(math.pi)
[vagrant@localhost python]$ python app.py
3.141592653589793
角度変換: math.degrees(), math.radians()
import math print(math.degrees(math.pi)) print(math.radians(180))
[vagrant@localhost python]$ python app.py
180.0
3.141592653589793
import math print(math.sin(math.radians(30))) print(round(sin30, 3)) print('{:.3}'.format(sin30)) print(format(sin30,'.3'))
[vagrant@localhost python]$ python app.py
0.49999999999999994
Traceback (most recent call last):
File “app.py”, line 4, in
print(round(sin30, 3))
NameError: name ‘sin30’ is not defined
あれ、sin30って使えない?
あ、sin30 = math.sin(math.radians(30)) で定義してないとダメだね。
import math cos60 = math.cos(math.radians(60)) print(cos60)
[vagrant@localhost python]$ python app.py
0.5000000000000001
誤差がああああああ