KEMBAR78
Python 4 Jalaj | PDF | Geometric Measurement | Length
0% found this document useful (0 votes)
44 views6 pages

Python 4 Jalaj

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)
44 views6 pages

Python 4 Jalaj

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
You are on page 1/ 6

Jalaj Pandey

BCA 5th

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

def setLength(self,length):
self.length = length
def setBredth(self,bredth):
self.bredth = bredth

def getLength(self):
return self.length
def getBredth(self):
return self.bredth

def Area(self):
return self.length * self.bredth
def Perimeter(self):
return 2*(self.length+self.bredth)
r = Rectangle()
r.setBredth(r.b)
r.setLength(r.a)
r.getBredth()
r.getLength()
print("breadth =", r.getBredth())
print("length =", r.getLength())
print("area =", r.Area())
print("Perimeter =", r.Perimeter())
2nd-
import datetime
from dateutil.relativedelta import *

class MyDate:
year = int(input('Enter a year: '))
month = int(input('Enter a month: '))
day = int(input('Enter a day: '))
date_original = datetime.date(year,month,day)
def addDays(self,n):
return datetime.timedelta(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:', b.strftime("%A"))

def diffDates(self):
date_1 = datetime.date.today()
date_2 = datetime.date(self.year,self.month,self.day)
diff = relativedelta(date_2,date_1)
print(f'The difference between today ({date_1}) and {date_2} is
{diff.years} years, {(diff.months)+(12*diff.years)} 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 + (self.addYears(y) +
self.addMonths(m) + self.addDays(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 = datetime.date.today() - (self.addYears(y) +
self.addMonths(m) + self.addDays(d))
print(f'Before {d} days, {m} months and {y} years from now, the
date was: ',date_previous)

D = MyDate()
D.weekday()
D.diffDates()
D.futureDate()
D.pastDate()
3rd-
class Student:
def __init__(self,roll,name,stream):
self.roll = roll
self.name = name
self.marks = [0]*5
self.stream = stream
self.percentage = 0
self.division = ""
self.grade = ""

def setMarks(self):
print(" enter 5 subjects marks :")
for i in range(1,6):
self.marks[i-1] = int(input(f'marks out of 100 in sub{i} :'))
def getStream(self):
return f' Stream : {self.stream}'
def Percentage(self):
self.percentage = sum(self.marks)/5
return f' Percentage is {self.percentage}'
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 {self.name} in
\t subject 1 :{grade(self.marks[0])}
\t subject 2 :{grade(self.marks[1])}
\t subject 3 :{grade(self.marks[2])}
\t subject 4 :{grade(self.marks[3])}
\t subject 5 :{grade(self.marks[4])}"""

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

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


stud1.setMarks()
print(stud1.Percentage())
print(stud1.getStream())
print(stud1.Grade())
print(stud1.Division())

You might also like