[Edit]
+
0
-
0

Python math.cos() working with degrees

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import math def calculate_cos(deg): rad = (math.pi / 180) * deg return math.cos(rad) x1 = 0.0 # beginning of calculation in degrees x2 = 90.0 # ending of calculation degrees dx = 15.0 # calculation step in degrees deg = x1 while deg <= x2: y = calculate_cos(deg) print("cos(", deg, " deg) = ", y) deg += dx # Output: # cos( 0.0 deg) = 1.0 # cos( 15.0 deg) = 0.9659258262890683 # cos( 30.0 deg) = 0.8660254037844387 # cos( 45.0 deg) = 0.7071067811865476 # cos( 60.0 deg) = 0.5000000000000001 # cos( 75.0 deg) = 0.25881904510252074 # cos( 90.0 deg) = 6.123233995736766e-17