Skip to content

PW_17

FornameException

python
class GuilhemError(Exception):
    def __init__(self, message):
        self.message = message

def whoIsTheBest():
    who = input("Wo is the best? ")
    if "guilhem" in who.lower() or "the teacher" in who.lower():
        print("You Won!")
    else:
        raise GuilhemError("For Sure?")

Vehicles

python
class DoNotGoThereError(Exception):
    def __init__(self, message):
        self.message = message

class vehicle:
    def __init__(self, wheels, weight, height, hasMotor = False):
        self.wheels = wheels
        self.weight = weight
        self.height = height
        self.hasMotor = hasMotor

    def canGoUnder(self, h:int)   -> bool: return self.height < h
    def canBeCarried(self, w:int) -> bool: return self.weight < w
    def canUseBicyclePath(self)   -> bool: return (self.wheels == 2) and (not self.hasMotor)

    def checkPath(self, hMax: int, wMax: int, bp: bool) -> bool:
        if bp:
            return self.canGoUnder(hMax) and self.canBeCarried(wMax) and self.canUseBicyclePath()
        return self.canGoUnder(hMax) and self.canBeCarried(wMax)

    def usePath(self, hMax: int, wMax: int, bp: bool) -> bool:
        if bp and not self.canUseBicyclePath():
            raise DoNotGoThereError("You are not a bicycle")
        if not self.canGoUnder(hMax):
            raise DoNotGoThereError("You are too hight to go there")
        if not self.canBeCarried(wMax):
            raise DoNotGoThereError("You are too heavy to go there")
    
bicycle = vehicle(2, 20, 160)
car = vehicle(4, 1300, 160, True)
truck = vehicle(4, 19000, 400, True)

def checkPathBis(veh: vehicle, hMax: int, wMax: int, bp: bool):
    return veh.checkPath(hMax, wMax, bp)

We would prefer usePath over checkPath when executing an action.

Released under the GPL-3.0 License.