Python - Ensuring a variable holds a positive number
问题 I am looking for an elegant way to ensure that a given variable remains positive. I have two variables that hold positive float numbers and I decrement them according to certain conditions. At the end I want to guarantee that I still have positive numbers (or 0 at most). The pseudo code looks something like this: list = [...] value1 = N value2 = M for element in list: if ... : value1 -= X if ... : value2 -= Y Is there a more elegant solution than just adding two ifs at the end? 回答1: I am