
Hi! Let’s use Python to convert Degree to Radian. We will be using Python 3.8.10. Let’s go! 🔥✨⚡
Radians and degrees are both units used to measure angles. The difference is that radians are the SI unit or International System of Units for measuring angles. The SI is an international known and accepted standard of measurement.
To convert degrees to radians we must multiply the angle in degrees by pi divided by 180°.
Let’s write our code:
import math
deg = float(input("Enter Degrees: "))
rad = deg*(math.pi/180)
print(f"{deg}° is equal to {rad} radians. ")
Let’s explain what is happening here:
- We import the math library which will allow us to use the math.pi constant.
- We provide a prompt to the user for the value in degrees to convert to radians, deg.
- We use the given formula to calculate radians rad.
- We print the value to the screen.
If all goes well, we will get the following output when the code executes:
#output
#Enter Degrees: 23
#23.0° is equal to 0.4014257279586958 radians.
Conversely, we can convert radians to degrees by reversing the process.
And this is our code:
import math
rad = float(input("Enter Radians: "))
deg = rad*(180/math.pi)
print(f"{rad} rad is equal to {deg}°. ")
Let’s explain what is happening here:
- We import the math library, as usual so we can access the math.pi constant.
- We prompt for the value in radians, rad
- We calculate the degrees deg according to the formula.
- Print the degrees to the screen.
If all goes well, we will see the following output:
#output
#Enter Radians: 2.5
#2.5 rad is equal to 143.2394487827058°.
Thanks for reading. We hope this helped. Good luck! 👌👌👌