0% found this document useful (0 votes)
263 views5 pages

Python Week 10 GrPA Sols

The document contains code for four Python classes - Calculator, StringManipulation, Shape and Time - that perform mathematical operations, string manipulation methods, define shapes and convert between time units respectively.

Uploaded by

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

Python Week 10 GrPA Sols

The document contains code for four Python classes - Calculator, StringManipulation, Shape and Time - that perform mathematical operations, string manipulation methods, define shapes and convert between time units respectively.

Uploaded by

rupakbasak632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

👉 GrPA 1

class Calculator:

def __init__(self,a,b):

self.a=a

self.b=b

def add(self):

return(self.a+self.b)

def multiply(self):

return(self.a * self.b)

def subtract(self):

return(self.a - self.b)

def quotient(self):

return(self.a//self.b)

def remainder(self):

return(self.a%self.b)

👉 GRPA 2

class StringManipulation:

def __init__(self,words):

self.words=words

def total_words(self):

return len(self.words)
def count(self,some_word):

return self.words.count(some_word)

def words_of_length(self,length):

l=[]

for each in self.words:

if(length==len(each)):

l.append(each)

return l

def words_start_with(self,char):

x=len(char)

f=True

l=[]

for each in self.words:

for i in range(x):

if(each[i]==char[i]):

l.append(each)

return l

def longest_word(self):

s=''

max=len(self.words[0])

for each in self.words:

if(len(each)>max):

max=len(each)

s=each

return s

def palindromes(self):

l=[]

for each in self.words:

if(each==each[::-1]):
l.append(each)

return l

s=StringManipulation(['the', 'this','wonderful', 'though', 'thou', 'many', 'mom',


'malayalam', 'manorama', 'was', 'wisdom','the'])

👉 GRPA 3

class Shape:

def __init__(self, name):

self.name = name

self.area = None

self.perimeter = None

def display(self):

print(f'{self.name} has an area of {self.area} and perimeter of


{self.perimeter}')

class Square(Shape):

def __init__(self, side):

super().__init__('Square')

self.side = side

self.compute_area()

self.compute_perimeter()

def compute_area(self):

self.area = self.side ** 2

def compute_perimeter(self):

self.perimeter = 4 * self.side
👉. GRPA 4

class Time:

def __init__(self, time):

self.time = time

def seconds_to_minutes(self):

self.minutes = self.time // 60

self.seconds = self.time % 60

return f'{self.minutes} min {self.seconds} sec'

def seconds_to_hours(self):

self.seconds_to_minutes()

self.hours = self.minutes // 60

self.minutes = self.minutes % 60

return f'{self.hours} hrs {self.minutes} min {self.seconds} sec'

def seconds_to_days(self):

self.seconds_to_hours()

self.days = self.hours // 24

self.hours = self.hours % 24

return f'{self.days} days {self.hours} hrs {self.minutes} min


{self.seconds} sec'
padh le bhai, nhi to 1 din berozgaar mrega

You might also like