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:
1 2 3 4 5 6 7 |
r=float(input("Input Radius : ")) area=3.14*r*r perimeter=2*3.14*r print("Area of Circle: ",area) print("Perimeter of Circle: ",perimeter) |
This code calculates the area and perimeter of a circle given its radius.
Here’s a brief explanation of how the code works:
- The user is prompted to enter the radius of the circle.
- The “area” variable is assigned the value of the circle’s area, which is calculated using the formula “pi * r^2”.
- The “perimeter” variable is assigned the value of the circle’s perimeter, which is calculated using the formula “2 * pi * r”.
- The area and perimeter of the circle are printed to the console.
Example 2: With round function
1 2 3 4 5 6 7 |
r=float(input("Input Radius : ")) area=round(3.14*r*r,2) perimeter=round(2*3.14*r,2) print("Area of Circle: ",area) print("Perimeter of Circle: ",perimeter) |
Output:
1 2 3 4 5 |
Input Radius : 17 Area of Circle: 907.46 Perimeter of Circle: 106.76 |
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:
- The user is prompted to enter the radius of the circle.
- 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.
- 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.
- The area and perimeter of the circle are printed to the console.
[…] Area and Perimeter of a Circle in Python […]
r=float(input(“input radius : “))
input radius=3
area=3.14*r*r
perimeter=2*3.14
print(“area of circle : “,area)
perimeter of circle=28.259999999999998
print(“perimeter of circle :”,perimeter)
perimeter of circle=56.519999999999996
plzz help,
8.A) Write a Python program to enter the radius of a circle and calculate the area of the circle.
B) Re-write the program to get the radius as a user input.