引發異常

如果你的程式碼遇到不知道如何處理的條件,例如不正確的引數,則應該引發相應的異常。

def even_the_odds(odds):
    if odds % 2 != 1:
        raise ValueError("Did not get an odd number")
    
    return odds + 1