Finding Cosine of an Angle Using Math Module

Write a Python program that uses the math module to find the cosine of a user input angle (in degrees). Return the cosine.

Example 1:

Input: 60
Output: 0.5

Example 2:

Input: 90
Output: 0.0

Use the cos() function from the math module. Make sure to convert the angle from degrees to radians.

import math

def cosine(angle):
    radians = math.radians(angle)
    return math.cos(radians)

# Test the function
print(cosine(60))  # Output: 0.5
print(cosine(90))  # Output: 0.0

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!