Area of Circle in Python
The formula for the area of a circle is Area = π × radius²
. In Python, we use either 3.14 or the math.pi
constant for π. Let's calculate area using both fixed and user-input radius.
क्वृम का क्षेत्रफल है एरिया = π × radius²
. Python में या तो 3.14 या math.pi
की मदद लेकर area calculate करते हैं।
Example 1: Using Fixed Radius
radius = 7
area = 3.14 * radius * radius
print("Area =", area)
Output:
Area = 153.86
Calculates area using fixed value of radius.
Fix radius की मदद से area calculate करता है।
Example 2: User Input for Radius
radius = float(input("Enter radius: ") )
area = 3.14 * radius * radius
print("Area =", area)
Output:
Enter radius: 5 Area = 78.5
Takes radius input from user and prints area.
User से radius लेकर area calculate करता है।
Example 3: Using math.pi
import math
radius = float(input("Enter radius: ") )
area = math.pi * radius ** 2
print("Area =", area)
Output:
Enter radius: 4 Area = 50.26548245743669
More accurate area using math.pi.
math.pi की मदद से accurate area निकलता है।