The radian is a unit of measure for angles used mainly in trigonometry. It is used as an alternative to degrees.
Whereas, in degrees a full circle is 360 degrees, in radians a full circle is 2π radians:
It is easy to convert an angle from degrees to radians and vice-versa using the following formulas:
Python Challenge
In this challenge we will write a program to convert an angle from degrees to radians or from radians to degrees based on the user’s choice. Our program will:
- Display a menu of options to the end user.
- Ask the end-user to choose an option from the menu.
- Ask the end-user to input an angle in the required unit.
- Calculate and output the angle in the alternative angle unit.
To structure this program we will make use of 3 subroutines as follows:
- A menu() function that displays the available options, ask the user for an otpion and return the selected option.
- A procedure called convertRadiansToDegrees() that ask the user to input an angle in radians, convert this angle using the appropriate conversion formula and output the angle in degrees.
- A procedure called convertDegreesToRadians() that ask the user to input an angle in degrees, convert this angle using the appropriate conversion formula and output the angle in radians.
We will then write an algorithm to complete this challenge, making use of our three subroutines.
Flowcharts
We have designed the flowcharts for the three subroutines and for the main algorithm.
Python Code
Your task is to complete the Python code for this challenge, using the flowcharts provided above.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area