Python code to calculate and display the value of Sine 45° and Cosine 30°

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:

  1. Import the math module: This module contains the necessary functions for trigonometric calculations.
  2. Convert degrees to radians: The trigonometric functions in the math module use radians, so we convert the angles from degrees to radians using math.radians().
    • math.radians(45) converts 45° to radians.
    • math.radians(30) converts 30° to radians.
  3. Calculate the sine of 45°: Use math.sin() on the angle in radians.
  4. Calculate the cosine of 30°: Use math.cos() on the angle in radians.
  5. Print the results: Use formatted strings to display the results clearly.

Leave a Reply

Your email address will not be published. Required fields are marked *