Degrees to Radians | Challenge

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

Degrees to Radians Challenge

Problem

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.

Example

degrees_to_rads(180) ## returns 3.1416
degrees_to_rads(90) ## returns 1.5708
degrees_to_rads(45) ## returns 0.7854

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