Skip to content
Snippets Groups Projects
Commit a45c80a4 authored by Daniel Moix's avatar Daniel Moix
Browse files

EL Demo

parent 294a47de
Branches
No related tags found
No related merge requests found
class EL:
def __init__(self, inches=0, feet=0, yards=0):
self.__inches = inches % 12
self.__feet = feet + inches // 12
self.__yards = yards + self.__feet // 3
self.__feet = self.__feet % 3
def getInches(self):
return self.__inches
def getFeet(self):
return self.__feet
def getYards(self):
return self.__yards
def totalInches(self):
return self.__inches + self.__feet * 12 + self.__yards * 36
def addInches(self, additionalInches):
newTotalInches = self.totalInches() + additionalInches
tempLength = EL(newTotalInches)
self.__yards = tempLength.getYards()
self.__feet = tempLength.getFeet()
self.__inches = tempLength.getInches()
def __add__(self, otherEL):
newEL = EL(self.totalInches() + otherEL.totalInches())
return newEL
if __name__ == "__main__":
len1 = EL(39)
print(len1.getInches(), "inches")
print(len1.getFeet(), "feet")
print(len1.getYards(), "yards")
print(len1.totalInches(), "inches total")
print("Adding 20 inches...")
len1.addInches(20)
print(len1.getInches(), "inches")
print(len1.getFeet(), "feet")
print(len1.getYards(), "yards")
print(len1.totalInches(), "inches total")
print("Making 2 EL objects to add together")
lenA = EL(11)
lenB = EL(9)
lenC = lenA + lenB
print(lenC.getInches(), "inches")
print(lenC.getFeet(), "feet")
print(lenC.getYards(), "yards")
print(lenC.totalInches(), "inches total")
\ No newline at end of file
import lect3
a = lect3.Clock()
b = lect3.Clock()
a.setTime(10, 10)
b.setTime(1, 7)
print(b.getTime())
left = 22
right = 7
print(left + right)
print(a + b)
\ No newline at end of file
import math
class Clock:
def __init__(self):
self.__hours = 12
self.__minutes = 0
def getHours(self):
return self.__hours
def getMinutes(self):
return self.__minutes
def getTime(self):
return f"{self.__hours}:{str(self.__minutes).zfill(2)}"
def setTime(self, newHours, newMinutes):
self.__hours = abs(newHours) % 13
self.__minutes = abs(newMinutes) % 60
#TODO: Fix this math
def nextMinute(self):
self.__minutes += 1
if self.__minutes > 59:
self.__minutes = 0
self.__hours += 1
self.__hours = self.__hours % 13
if __name__ == "__main__":
myClock = Clock()
myClock.setTime(10, 2)
print(myClock.getTime())
import old
print("This code is in the new file")
old.main()
old.printHappyFace()
\ No newline at end of file
def main():
print("This code is in the old file")
def printHappyFace():
print("😘")
if __name__ == "__main__":
main()
\ No newline at end of file
class EL:
def __init__(self, inches=0, feet=0, yards=0):
self.__inches = inches % 12
self.__feet = feet + inches // 12
self.__yards = yards + self.__feet // 3
self.__feet = self.__feet % 3
def getInches(self):
return self.__inches
def getFeet(self):
return self.__feet
def getYards(self):
return self.__yards
def totalInches(self):
return self.__inches + self.__feet * 12 + self.__yards * 36
def addInches(self, additionalInches):
newTotalInches = self.totalInches() + additionalInches
tempLength = EL(newTotalInches)
self.__yards = tempLength.getYards()
self.__feet = tempLength.getFeet()
self.__inches = tempLength.getInches()
def __add__(self, otherEL):
newEL = EL(self.totalInches() + otherEL.totalInches())
return newEL
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment