You are on page 1of 3

Navarro, Jules Rhenz February 24, 2022

1-CPE-A OOP

1. Source code:

class triangle:
lenght = 0
height = 0
width = 0
answer1 = 0
answer2 = 0

def __init__(self, lenght, width, height):


self.lenght = lenght
self.width = width
self.height = height

def display(self):
print("A:",self.lenght,"units","\nB:",self.height,"units","\nC:",self.width,"units",)
print()
print("The perimeter of the triangle is:",self.answer1)
print()
print("Base:",self.width,"units","\nHeight:",self.height,"units")
print()
print("The area of the triangle is:",self.answer2)

def calculate(self):
self.answer1 = self.lenght + self.height + self.width
self.answer2 = 0.5 * self.width * self.height

obj = triangle(3, 4, 5)
obj.calculate()
obj.display()
screenshot of the working output:

2. Source code:

import time

class Dog:
drinktime = 0

def SetDrinkTime(self, val:int):


Dog.drinktime = val

def GetDrinkTime(self):
return Dog.drinktime

def needstogo(self):
val1 = self.GetDrinkTime()
if val1 == 0:
return ("The dog haven't drink any water")
else:
res = int(t.tm_hour) - val1
if res >= 4:
return True
else:
return False

class DogOwner:
def takeforwalk(self):
if obj1.needstogo() == True:
return True
elif obj1.needstogo() == True:
return False
else:
return ("The dog haven't drink any water")

obj1 = Dog()
t = time.localtime()
time_key = int(input("When is the last time that the dog drink? "))
obj1.SetDrinkTime(time_key)
obj2 = DogOwner()
print("The dog needs to go right now.",obj1.needstogo())
print()
print("Taking the dog for a walk.",obj2.takeforwalk())

screenshot of working output:

You might also like