0% found this document useful (0 votes)
6 views6 pages

Python Classes for Rectangle and Date Calculations

The document contains code defining classes for Rectangle, MyDate, and Student. The Rectangle class defines methods to set length and breadth, get length and breadth, and calculate area and perimeter. The MyDate class defines methods to add/subtract days, months, years from a date, get the weekday, calculate date differences, and get future/past dates. The Student class defines methods to set marks, get stream, calculate percentage, assign grade and division based on percentage.

Uploaded by

Jalaj Pandey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Python Classes for Rectangle and Date Calculations

The document contains code defining classes for Rectangle, MyDate, and Student. The Rectangle class defines methods to set length and breadth, get length and breadth, and calculate area and perimeter. The MyDate class defines methods to add/subtract days, months, years from a date, get the weekday, calculate date differences, and get future/past dates. The Student class defines methods to set marks, get stream, calculate percentage, assign grade and division based on percentage.

Uploaded by

Jalaj Pandey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

Jalaj Pandey

BCA 5th

class Rectangle:
a = int(input("enter the length ="))
b = int(input("enter the bredth ="))
def __init__(self):
[Link] = 1
[Link] = 1

def setLength(self,length):
[Link] = length
def setBredth(self,bredth):
[Link] = bredth

def getLength(self):
return [Link]
def getBredth(self):
return [Link]

def Area(self):
return [Link] * [Link]
def Perimeter(self):
return 2*([Link]+[Link])
r = Rectangle()
[Link](r.b)
[Link](r.a)
[Link]()
[Link]()
print("breadth =", [Link]())
print("length =", [Link]())
print("area =", [Link]())
print("Perimeter =", [Link]())
2nd-
import datetime
from [Link] import *

class MyDate:
year = int(input('Enter a year: '))
month = int(input('Enter a month: '))
day = int(input('Enter a day: '))
date_original = [Link](year,month,day)
def addDays(self,n):
return [Link](n)

def addMonths(self,m):
return relativedelta(months= m)

def addYears(self,y):
return relativedelta(years= y)
def weekday(self):
b = self.date_original
print(f'The weekday of {b} is:', [Link]("%A"))

def diffDates(self):
date_1 = [Link]()
date_2 = [Link]([Link],[Link],[Link])
diff = relativedelta(date_2,date_1)
print(f'The difference between today ({date_1}) and {date_2} is
{[Link]} years, {([Link])+(12*[Link])} months and {(date_2 -
date_1).days} days')

def futureDate(self):
d = int(input("Days to add:"))
m = int(input("Months to add:"))
y = int(input("Years to add:"))
date_next = self.date_original + ([Link](y) +
[Link](m) + [Link](d))
print(f'After {d} days, {m} months and {y} years from
{self.date_original}, the date will be: ',date_next)

def pastDate(self):
d = int(input("Days to subtract:"))
m = int(input("Months to subtract:"))
y = int(input("Years to subtract:"))
date_previous = [Link]() - ([Link](y) +
[Link](m) + [Link](d))
print(f'Before {d} days, {m} months and {y} years from now, the
date was: ',date_previous)

D = MyDate()
[Link]()
[Link]()
[Link]()
[Link]()
3rd-
class Student:
def __init__(self,roll,name,stream):
[Link] = roll
[Link] = name
[Link] = [0]*5
[Link] = stream
[Link] = 0
[Link] = ""
[Link] = ""

def setMarks(self):
print(" enter 5 subjects marks :")
for i in range(1,6):
[Link][i-1] = int(input(f'marks out of 100 in sub{i} :'))
def getStream(self):
return f' Stream : {[Link]}'
def Percentage(self):
[Link] = sum([Link])/5
return f' Percentage is {[Link]}'
def Grade(self):
def grade(totalmarks):
if totalmarks >= 90:
grade = 'A'
elif totalmarks < 90 and totalmarks >= 80:
grade = "B"
elif totalmarks < 80 and totalmarks >= 65:
grade = 'C'
elif totalmarks < 65 and totalmarks >= 40:
grade = "D"
elif totalmarks < 40:
grade = "E"
return grade
return f"""Grade of {[Link]} in
\t subject 1 :{grade([Link][0])}
\t subject 2 :{grade([Link][1])}
\t subject 3 :{grade([Link][2])}
\t subject 4 :{grade([Link][3])}
\t subject 5 :{grade([Link][4])}"""

def Division(self):
if [Link] >= 60:
division = "I"
elif [Link] < 60 and [Link] >= 50:
division = "II"
elif [Link] < 50 and [Link] >= 35:
division = "III"
return f'Division is {division}'

stud1 = Student(name = "Jalaj Pandey", roll = 1, stream = "Science")


[Link]()
print([Link]())
print([Link]())
print([Link]())
print([Link]())

You might also like