Trigonometry is an important branch of mathematics that deals with the study of relationships between the sides and angles of triangles. It finds applications in various fields, such as physics, engineering, and computer graphics. In this blog post, we will show you how to build a simple trigonometry calculator in Python.

First, we need to import the math module, which provides access to various mathematical functions. This module contains functions for trigonometric operations, such as sine, cosine, and tangent.

import math

Next, we will prompt the user to enter an angle in degrees using the input() function. We will convert the angle from degrees to radians using the math.radians() function, which takes an angle in degrees and returns the angle in radians.

angle_degrees = float(input("Enter an angle in degrees: "))
angle_radians = math.radians(angle_degrees)

We can now calculate the sine, cosine, and tangent of the angle using the math.sin(), math.cos(), and math.tan() functions respectively. We will store the results in the variables sin_angle, cos_angle, and tan_angle.

sin_angle = math.sin(angle_radians)
cos_angle = math.cos(angle_radians)
tan_angle = math.tan(angle_radians)

Finally, we will print out the results using the print() function and formatted strings.

print(f"The sine of {angle_degrees} degrees is {sin_angle:.3f}")
print(f"The cosine of {angle_degrees} degrees is {cos_angle:.3f}")
print(f"The tangent of {angle_degrees} degrees is {tan_angle:.3f}")

Putting it all together, here is the complete code for our trigonometry calculator:

import math

angle_degrees = float(input("Enter an angle in degrees: "))
angle_radians = math.radians(angle_degrees)

sin_angle = math.sin(angle_radians)
cos_angle = math.cos(angle_radians)
tan_angle = math.tan(angle_radians)

print(f"The sine of {angle_degrees} degrees is {sin_angle:.3f}")
print(f"The cosine of {angle_degrees} degrees is {cos_angle:.3f}")
print(f"The tangent of {angle_degrees} degrees is {tan_angle:.3f}")

To use this calculator, simply run the code and enter an angle in degrees when prompted. The program will then calculate and display the sine, cosine, and tangent of the angle.

For example, if we enter an angle of 45 degrees, the program will output:

Enter an angle in degrees: 45
The sine of 45.0 degrees is 0.707
The cosine of 45.0 degrees is 0.707
The tangent of 45.0 degrees is 1.000

Python provides a simple and effective way to build a trigonometry calculator that can calculate the sine, cosine, and tangent of an angle in degrees. The math module in Python provides access to various mathematical functions, including those needed for trigonometric operations.