def f(x):
    return -300*x + 1
    
def tab(a,b):
    L = [ f(x) for x in range(a,b+1) ]
    M = max( [ abs(x) for  x in L ])
    w = len( str(M) )
    if w < 4:
        w = 4
    if M not in L:
        w += 1
        
    top_line_col = ' ' + '-'*(w+2)
    top_line = top_line_col * ( len(L) + 1 ) # ligne du haut
    
    formatage = '{:^'+str(w+2)+'}'
    
    x_line = '|' + formatage.format('x') 
    for x in range(a,b+1):
        x_line += '|' + formatage.format(x) 
    x_line += '|'
    
    y_line = '|' + formatage.format('f(x)') 
    for y in L:
        y_line += '|' + formatage.format(y) 
    y_line += '|'
    
    tab = top_line + '\n' + x_line + '\n' + top_line + '\n' + y_line + '\n' + top_line
    
    return tab


print( tab(-5,5) )

