Convert Angles Between Radians and Degrees

PythonPythonBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In mathematics, angles can be measured in different units such as degrees and radians. Radians are a unit of measurement for angles that are commonly used in mathematics and physics. However, sometimes we may need to convert an angle from radians to degrees to make it more understandable. In this challenge, you will be asked to write a Python function that converts an angle from radians to degrees.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/PythonStandardLibraryGroup(["`Python Standard Library`"]) python/BasicConceptsGroup -.-> python/comments("`Comments`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/ModulesandPackagesGroup -.-> python/using_packages("`Using Packages`") python/ModulesandPackagesGroup -.-> python/standard_libraries("`Common Standard Libraries`") python/PythonStandardLibraryGroup -.-> python/math_random("`Math and Random`") subgraph Lab Skills python/comments -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} python/function_definition -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} python/importing_modules -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} python/using_packages -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} python/standard_libraries -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} python/math_random -.-> lab-13707{{"`Convert Angles Between Radians and Degrees`"}} end

Radians to Degrees

Write a Python function called rads_to_degrees that takes a single argument rad, which is a float representing an angle in radians. The function should return the angle in degrees as a float. You can use the following formula to convert an angle from radians to degrees:

degrees = radians * (180 / pi)

where pi is a constant value representing the ratio of the circumference of a circle to its diameter, which is approximately equal to 3.14159.

Your function should import the pi constant from the math module.

from math import pi

def rads_to_degrees(rad):
  return (rad * 180.0) / pi
from math import pi

rads_to_degrees(pi / 2) ## 90.0

Summary

In this challenge, you have written a Python function that converts an angle from radians to degrees. You have used the pi constant from the math module and the radian to degree formula to perform the conversion.

Other Python Tutorials you may like