Python

Python Program to Calculate Area and Perimeter of Circle2 min read

The circle’s circumference — the measure of the total length around the shape — is determined based on the fixed ratio of Pi. In degrees, a circle is equal to 360° and Pi (p) is the fixed ratio equal to 3.14.

Area: p * r * r




Perimeter: 2 * p * r

Python Code:

This code calculates the area and perimeter of a circle given its radius.

Here’s a brief explanation of how the code works:

  1. The user is prompted to enter the radius of the circle.
  2. The “area” variable is assigned the value of the circle’s area, which is calculated using the formula “pi * r^2”.
  3. The “perimeter” variable is assigned the value of the circle’s perimeter, which is calculated using the formula “2 * pi * r”.
  4. The area and perimeter of the circle are printed to the console.

Example 2: With round function

Output:

This code calculates the area and perimeter of a circle given its radius and rounds the results to two decimal places.

Here’s a brief explanation of how the code works:

  1. The user is prompted to enter the radius of the circle.
  2. The “area” variable is assigned the value of the circle’s area, which is calculated using the formula “pi * r^2”. The result is then rounded to two decimal places using the “round” function.
  3. The “perimeter” variable is assigned the value of the circle’s perimeter, which is calculated using the formula “2 * pi * r”. The result is then rounded to two decimal places using the “round” function.
  4. The area and perimeter of the circle are printed to the console.

3 Comments

Leave a Comment