Professional Documents
Culture Documents
Python Week 10 GrPA Sols
Python Week 10 GrPA Sols
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=[]
if(length==len(each)):
l.append(each)
return l
def words_start_with(self,char):
x=len(char)
f=True
l=[]
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])
if(len(each)>max):
max=len(each)
s=each
return s
def palindromes(self):
l=[]
if(each==each[::-1]):
l.append(each)
return l
👉 GRPA 3
class Shape:
self.name = name
self.area = None
self.perimeter = None
def display(self):
class Square(Shape):
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:
self.time = time
def seconds_to_minutes(self):
self.minutes = self.time // 60
self.seconds = self.time % 60
def seconds_to_hours(self):
self.seconds_to_minutes()
self.hours = self.minutes // 60
self.minutes = self.minutes % 60
def seconds_to_days(self):
self.seconds_to_hours()
self.days = self.hours // 24
self.hours = self.hours % 24