
Write a Python program to create a class representing a Circle. Include methods to calculate its area and perimeter.

Write a Python program to create a person class. Include attributes like name, country, and date of birth. Implement a method to determine the person’s age.
import math
class Circle:
def init(self, radius):
self.radius = radius
def from_diameter(cls, diameter):
return cls(diameter / 2)
def calculate_area(self):
return math.pi * self.radius ** 2
def calculate_perimeter(self):
return 2 * math.pi * self.radius
radius = float(input("Enter the radius of the circle: "))
circle = Circle(radius)
print(“Area:”, circle.calculate_area())
print(“Perimeter:”, circle.calculate_perimeter())
import math
class Circle:
def init(self,radius):
self.radius = radius
def calculate_area(self):
result = math.pi *self.radius**2
return result
def calculate_perimeter(self):
result= 2 * math.pi * self.radius
return result
radius = int(input("Enter the radius of the circle: "))
obj = Circle(radius)
area = obj.calculate_area()
perimeter = obj.calculate_perimeter()
print(f"Circle with radius {radius}:“)
print(f"Area: {area}”)
print(f"Perimeter : {perimeter}")
from datetime import datetime
class Person:
def init(self, Name, Country, DOB):
self.name = Name
self.country = Country
self.dob = DOB
def calculate_age(self):
Today = datetime.today()
Birth_Date = datetime.strptime(self.dob, '%Y%m%d')
Age = Today.year  Birth_Date.year  ((Today.month, Today.day) < (Birth_Date.month, Birth_Date.day))
return Age
name = input("Enter the person’s name: ")
country = input("Enter the person’s country: ")
dob = input("Enter the person’s date of birth (YYYYMMDD): ")
Person1 = Person(name, country, dob)
Age = Person1.calculate_age()
print(f"{Person1.name} is {Age} years old.")
#Write a Python program to create a class representing a Circle. Include methods to calculate its area and perimeter
import math
class Circle:
def __init__(self,radius):
self.radius=radius
def area_circle(self):
area= math.pi*self.radius**2
return area
def perimeter_circle(self):
perimeter=2*math.pi*self.radius
return perimeter
radius=float(input("enter radius"))
c=Circle(radius)
print("area of circle:",c.area_circle())
print("perimeter of circle:",c.perimeter_circle())
output:
enter radius1.2
area of circle: 4.523893421169302
perimeter of circle: 7.5398223686155035
1. Write a Python program to create a person class. Include attributes like name, country, and date of birth. Implement a method to determine the person’s age.
from datetime import date
class Person:
def __init__(self, name, country, date_of_birth):
self.name = name
self.country = country
self.date_of_birth = date_of_birth
def calculate_age(self):
today = date.today()
age = today.year  self.date_of_birth.year
if today < date(today.year, self.date_of_birth.month, self.date_of_birth.day):
age = 1
return age
person1 = Person("Mamatha", "India", date(1990, 3, 1))
print("Person 1:")
print("Name:", person1.name)
print("Country:", person1.country)
print("Date of Birth:", person1.date_of_birth)
print("Age:", person1.calculate_age())
output:
Person 1:
Name: Mamatha
Country: India
Date of Birth: 19900301
Age: 33
very good. really appreciated your effort
very good. please keep practicing.
very good. keep going.
very good and neat reply. appriciated
very good. keep going
Ans:
import math
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius ** 2
perimeter = 2 * math.pi * radius
print(“Area of the circle:”, area)
print(“perimeter of the circle:”, perimeter)
very good.please keep your practice