Question: Python OOP approach (class) Problem: calculate area and perimeter of a circle after calculating the distance between two points I have been playing around my
Python OOP approach (class) Problem: calculate area and perimeter of a circle after calculating the distance between two points
I have been playing around my code, written the formulas, but need help in reorganizing to execute python codes as expected.
- User enters as a pair of coordinates,
- the code calculates the distance formula which in turn is the radius of the circle,
- then I will calculate the (a) area and (b) perimeter of the circle based on the entered coordinates of the points.
I defined my formulas in a class circle. Need help in rewriting the whole code below to work. Right now only the inputs work.
```
import math class Circle(): def __init__(self, r, a, p): self.radius = r self.area = a self.perimeter = p def point_distance(x1, y1, x2, y2): r = math.sqrt(((y2-y1)**2) + ((x2-x1)**2)) return r def area(self): a = 2*math.pi*self.radius**2 return a def perimeter(self): return 2*self.radius*3.14 x1, y1 = input("Enter the coordinates of the center of the circle (x, y): ").split(',') x2, y2 = input("Enter the coordinates of the point on the circle (x, y): ").split(',') x1,y1 = int(x1), int(y1) x2,y2 = int(x2), int(y2) # distance = math.sqrt((y2-y1)**2) + ((x2-x1)**2) print(f"The radius of the circle is {point_distance(x1, y1, x2, y2):.2f}") ## the code is not returning anything. Only the input works. ```
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
