Question: Perform calculations using input & variables in Python: 1. Ask the user to choose how to calculate the circumference of a circle. The user should
Perform calculations using input & variables in Python:
1. Ask the user to choose how to calculate the circumference of a circle.
The user should be able to enter either "r" for radius or "d" for diameter. Your code should present a question to the user, like the following example (you can be creative here if you would like). Add a space or a line break to make the user's entry more comfortable:
MESSAGE: "How would you like to calculate the circumference (r/d)? "
Validate that the user entered either "r" or "d". If the user entered something else, provide a message that states the following, and exit or naturally end the program:
MESSAGE: "Please enter either 'r' or 'd'."
2. Ask the user what length to use for radius or diameter.
Assuming the user enters "r" or "d", next, we need to know the length. Prompt the user to enter a value for length, for example:
MESSAGE: "Please enter the length of your measurement: "
3. Validate that the entered value is a number greater than 0.
After the user enters the length, if the user's input is not a number, print a message that states the following and exit the program. Do the same thing if the number is below 0.
MESSAGE: "Please enter a numeric value greater than 0."
4. Using conditional statements as needed, decide how to calculate the circumference.
The circumference is calculated as follows:
Using radius: circumference = 2radiuspi
Using diameter: circumference = diameterpi
NOTE: An acceptable value of PI for this lab is: 3.14159
5. Print the resulting value, rounding to the nearest third decimal place.
When completed, your user should see the following message:
MESSAGE: "Using the length of
For example, if the user selected "d" for diameter, and entered 10, the following message would be displayed:
EXAMPLE: "Using the length of diameter 10, the circumference of the circle is 31.416."
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
