Ad
Fundamentals
Restricted

saved some chars and and operations by just cheking the least significant bit.

Code
Diff
  • is_even=lambda*x:not(x[False]&True)
    • is_even=lambda*x:not(x[len("")]%(True+True))
    • is_even=lambda*x:not(x[False]&True)

a more maximalist version with type annotations like a java programmer who is learning python. But wait... a twist, mypy doesn't like this if you check the type annotations, a really good writeup of the issue can be found here: https://stackoverflow.com/questions/69334475/how-to-hint-at-number-types-i-e-subclasses-of-number-not-numbers-themselv/69383462#69383462. I hope I get to share this bit of serendipity with someone one day.

Code
Diff
  • from numbers import Number
    def kube (l: Number, w: Number, h: Number) -> Number:
        if any(not isinstance(x, Number) for x in (l, w, h)):
            raise TypeError("sides must be numeric")  
        if any(x < 0 for x in (l, w, h)):
            raise ValueError("Cube edges must have positive length")  
        else:
            return l * w * h
    • kube = lambda l, w, h: "Invalid Cube" if any(x < 0 for x in (l, w, h)) else l * w * h
    • from numbers import Number
    • def kube (l: Number, w: Number, h: Number) -> Number:
    • if any(not isinstance(x, Number) for x in (l, w, h)):
    • raise TypeError("sides must be numeric")
    • if any(x < 0 for x in (l, w, h)):
    • raise ValueError("Cube edges must have positive length")
    • else:
    • return l * w * h