return sin(xelsereturn def test_f() exp - exp pi/ exp tol - assert abs( ( )-exp tolf'failed for { }assert abs( ( )-exp tolf'failed for { }assert abs( ( )-exp tolf'failed for { }note here thatsince we compare floating point numberswhich have finite precision on computerwe compare with tolerance rather than the equality =the tolerance tol is some small numberchosen by the programmerthat is small enough that we would consider difference of this magnitude insignificantbut greater than the machine precision ( in practicecomparing floats using =will quite often workbut sometimes it fails and it is impossible to predict when this will happen the code therefore becomes unreliableand it is much safer to compare with tolerance on the other handwhen we work with integers we can always use =one could argue that the test function code above is quite inelegant and repetitivesince we repeat the same lines multiple times with very minor changes since we only repeat three linesit might not be big deal in this casebut if we included more assert statements it would certainly be both boring and error-prone to write code in this way in the previous we introduced loops as much more elegant tool or performing such repetitive tasks using lists and for loopthe example above can be written as followsfrom math import sinpi def ( )if < <pireturn sin(xelsereturn def test_f()x_vals [- pi/ exp_vals [ tol - for xexp in zip(x_valsexp_vals)assert abs( ( )-exptolf'failed for { }expected {exp}but got { ( )}python tools for automatic testing an advantage of following the naming convention for test functions defined above is that there are tools that can be used to automatically run all the test functions in file or folder and report if any bug has sneaked into the code the use of such automatic testing tools is essential in larger development projects with multiple people