How to convert radian to degree in Python

We all have dealt with radians and degrees in our school and college days. Yes, in Mathematics and Physics.
Radians and Degree are used to represent angles. For eg, 1.4 radians or 30 degrees.
In this tutorial, we will learn how to convert radian to degree in Python.

Radian to Degree in Python

There are two methods for the conversion.

  1. Obvious Method, which is too obvious.
  2. Python degrees() method.

Let’s start with the first one.

Using formula(The obvious method)

We all know the formula for converting radian into degree,
degree=(radian*180)/pi

Let’s write the code in Python.

import math
def degree(x):
    pi=math.pi
    degree=(x*180)/pi
    return degree

This is a simple code written in Python in which we define a function degree(x) which takes radian value as a parameter and returns the corresponding value in degree.
Here, We import math library which provides different mathematical functions, pi in this case.
math.pi returns the value of pi which is stored in a variable x.

Finally, Let’s call the function.

print("Value in Degree:",degree(1.5))

Output:

Value in Degree: 85.94366926962348

 

degrees() method

math library includes a method degrees() which takes radian value as parameter and returns value in Degree.

Again, we define a function degree(x) which takes radian value as a parameter and returns the corresponding value in degree.

import math
def degree(x):
    x=math.degrees(x)
    return x

Now calling the function in the same way as in the previous method.

print("Value in Degree:",degree(1.5))

We get the output:

Value in Degree: 85.94366926962348

We hope you got a clear idea on How to convert radian to degree in Python.

In addition, radians() is a method that takes degree value as parameter and returns value in radians.

Also, Learn:

Leave a Reply