from tabulate import tabulate from numpy import arange from numpy import pi as CONSTANT_P from numpy import sin def get_function_tab_values( function, range_from, range_till, step ): function_values = [] for x in arange(range_from, range_till + step, step): function_values.append( [ x, function(x) ] ) return function_values def tab_function( name, function, range_from, range_till, steps ): for step in steps: function_values = get_function_tab_values(function, range_from, range_till, step) print( 'Function: {0}, step: {1}'.format(name, step) ) print( tabulate(function_values, headers=['x', 'y']) ) print() def function_1(x): return x ** 3 def function_2(x): return 4 * sin( CONSTANT_P * x + CONSTANT_P / 8 ) - 1 tab_function( 'x^3', function_1, -2, 2, [0.01, 0.1, 0.25] ) tab_function( '4sin(px+p/8)-1', function_2, -10, 10, [0.25, 1] )