引发异常

如果你的代码遇到不知道如何处理的条件,例如不正确的参数,则应该引发相应的异常。

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