Radians to Degrees | Challenge

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/FunctionsGroup(["`Functions`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/ErrorandExceptionHandlingGroup(["`Error and Exception Handling`"]) python(("`Python`")) -.-> python/PythonStandardLibraryGroup(["`Python Standard Library`"]) 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/ErrorandExceptionHandlingGroup -.-> python/custom_exceptions("`Custom Exceptions`") python/PythonStandardLibraryGroup -.-> python/math_random("`Math and Random`") subgraph Lab Skills python/function_definition -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} python/importing_modules -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} python/using_packages -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} python/standard_libraries -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} python/custom_exceptions -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} python/math_random -.-> lab-13175{{"`Radians to Degrees | Challenge`"}} end

Radians to Degrees Challenge

Problem

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.

Example

Here is an example of how your function should work:

from math import pi

assert 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