M.Sc Python Programming Assignment 31

M.Sc Python Programming Assignments

Assignment 31

Question:

Write a Python class named Circle constructed by a radius and two methods which will 

compute the area and the perimeter of a circle

Code:

				
					import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def compute_area(self):
        return math.pi * self.radius ** 2

    def compute_perimeter(self):
        return 2 * math.pi * self.radius

# Example usage
radius = float(input("Enter the radius of the circle: "))

circle = Circle(radius)

area = circle.compute_area()
perimeter = circle.compute_perimeter()

print("Area of the circle:", area)
print("Perimeter of the circle:", perimeter)

				
			

Output:

				
					Enter the radius of the circle: 44
Area of the circle: 6082.12337734984
Perimeter of the circle: 276.46015351590177


				
			
Tech Amplifier Final Logo