Open science and good programming practice


In [1]:
assert True, "This is an assert statement"

In [2]:
num = 2.003

In [3]:
assert num > 2, "value must be > 2"

In [4]:
assert num < 2.001, "value can only be a bit bigget than 2"


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-80cc036c5483> in <module>()
----> 1 assert num < 2.001, "value can only be a bit bigget than 2"

AssertionError: value can only be a bit bigget than 2

In [13]:
def temp_c_to_k(temp_in_c):
    """convert temperature from C to K
    """
    temp_in_k = temp_in_c + 273.15
    assert temp_in_k > 0, "K must be positive"
    return temp_in_k

In [16]:
print(temp_c_to_k(-274))


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-16-ee9b9e205772> in <module>()
----> 1 print(temp_c_to_k(-274))

<ipython-input-13-e01f4670580d> in temp_c_to_k(temp_in_c)
      3     """
      4     temp_in_k = temp_in_c + 273.15
----> 5     assert temp_in_k > 0, "K must be positive"
      6     return temp_in_k

AssertionError: K must be positive

In [ ]: