Python: math Module, atan2(), degrees()
After executing calc_angle(AB, BC)
in the CLI, input two numbers which represent lengths of opposite side AB
and adjacent side BC
for the calculation of ϴ° or ∠MBC (see below). atan2()
returns a value in radians, which is converted to ϴ° by thedegrees()
function.
$ python calc_angle.py
10
10
45°
The workings of calc_angle(AB, BC)
are demonstrated below:
>>> from math import atan2, degrees
>>> atan2(10, 10)
0.7853981633974483
>>> degrees(atan2(10, 10))
45.0
>>> round(degrees(atan2(10, 10)))
45
>>> str(round(degrees(atan2(10, 10)))) + '°'
'45°'
>>> print(str(round(degrees(atan2(10, 10)))) + '°')
45°