import math # Convert degrees to radians angle_45_degrees_in_radians = math.radians(45) angle_30_degrees_in_radians = math.radians(30) # Calculate sine of 45 degrees sine_45 = math.sin(angle_45_degrees_in_radians) # Calculate cosine of 30 degrees cosine_30 = math.cos(angle_30_degrees_in_radians) # Display the results print(f"Sine of 45 degrees is: {sine_45}") print(f"Cosine of 30 degrees is: {cosine_30}")
Output:
Sine of 45 degrees is: 0.7071067811865476
Cosine of 30 degrees is: 0.8660254037844387
Explanation:
- Import the
math
module: This module contains the necessary functions for trigonometric calculations. - Convert degrees to radians: The trigonometric functions in the
math
module use radians, so we convert the angles from degrees to radians usingmath.radians()
.math.radians(45)
converts 45° to radians.math.radians(30)
converts 30° to radians.
- Calculate the sine of 45°: Use
math.sin()
on the angle in radians. - Calculate the cosine of 30°: Use
math.cos()
on the angle in radians. - Print the results: Use formatted strings to display the results clearly.