[Solved] Basic Python Functions (Mathematics involved)


The formula is pretty basic, it say: The function ‘f’ for provided argument ‘S’ returns value ‘K’ if value ‘S’ is less or equal then the value ‘K’, if the value ‘S’ is greater then the value ‘K’ AND lower then the value ‘2*K’ – return value ‘2*K-S’, otherwise return 0.

Python:

def A(S,K):
    result = 0
    if S <= K:
        result = K
    elif K < S < 2*K:
        result = 2*K-S
    return result

solved Basic Python Functions (Mathematics involved)