Back

Code Challenge: Area of a Circle

Difficulty  

divider

Objective

Calculate the area of a circle from a radius entered by the user.

Use math.pi from Activity 1.9 rather than typing out 3.14159 — that is exactly what the math module is for.

Skills to Practice

  • Prompting a user for input
  • Saving user input to variables
  • Converting input to the correct data type
  • Performing arithmetic calculations
  • Formatting custom output using variables
  • Using a constant from the math module

Tasks

  • Create a new Python program named cc-area-of-a-circle.
  • Prompt the user to enter the radius of the circle.
  • Calculate the area. Formula: Area = π × radius2
  • Optionally, round the answer to two decimal places.
  • Display the calculated area in a clear, formatted way.

Sample Output

Sample Output
--- Circle Area Calculator ---
Enter the radius of the circle: 5 [Enter]
The area of the circle is 78.54

Commence Challenge