Search code examples
pythonareacalculation

Python calculate area of circle from two given points A and B


new to Python and programming in general. First homework and a little stumped on this question.

Given two points A(x1, y1) and B(x2, y2) in the plane. Write a program to calculate the area of a circle centered as A and go through B. Hint: The radius of the circle will be the distance between A and B. AB2 = ((x1 – x2)2 + (y1 – y2)2). R = AB2 ** 0.5.

I am using PyCharm community edition and python latest version


Solution

  • This is more of a basic math problem not realy a code problem but anyway:

    PI=3.14
    
    pointa={"x1":1,"y1":1}
    pointb={"x2":2,"y2":2}
    r=((pointa['x1']-pointb['x2'])**2 +(pointa['y1']-pointb['y2'])**2)**0.5
    area=PI*(r**2)
    
    print(area)
    

    replace the x1,x2,y1,y2 values as you wish in the pointa and pointb dictionaries