Convert Angle Degrees to Radians

PythonPythonBeginner
Practice Now

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

Introduction

In mathematics, angles can be measured in degrees or radians. Radians are the standard unit of angular measure, used in many areas of mathematics and physics. In this challenge, you will be asked to write a function that converts an angle from degrees to radians.


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-13618{{"`Convert Angle Degrees to Radians`"}} python/function_definition -.-> lab-13618{{"`Convert Angle Degrees to Radians`"}} python/importing_modules -.-> lab-13618{{"`Convert Angle Degrees to Radians`"}} python/using_packages -.-> lab-13618{{"`Convert Angle Degrees to Radians`"}} python/standard_libraries -.-> lab-13618{{"`Convert Angle Degrees to Radians`"}} python/math_random -.-> lab-13618{{"`Convert Angle Degrees to Radians`"}} end

Degrees to Radians

Write a function degrees_to_rads(deg) that takes an angle in degrees as an argument and returns the angle in radians. Your function should use the following formula to convert degrees to radians:

radians = (degrees * pi) / 180.0

where pi is a constant value representing the ratio of the circumference of a circle to its diameter (approximately 3.14159).

Your function should return the angle in radians rounded to 4 decimal places.

from math import pi

def degrees_to_rads(deg):
  return (deg * pi) / 180.0
degrees_to_rads(180) ## ~3.1416

Summary

In this challenge, you have learned how to convert an angle from degrees to radians using the formula radians = (degrees * pi) / 180.0. You have also written a function that implements this formula and returns the angle in radians rounded to 4 decimal places.

Other Python Tutorials you may like