Function return value of x instead of y
<p>f(x) represents the function of a triangular waveform. In which you input the value x and it returns you the associated y value. However my function returns x every time instead of y. For example f(1) should give 2/pi instead of 1.</p>

<pre><code>def f(x):

    y=x

    if x in arange(-math.pi,-math.pi/2):
        y=(-2/math.pi)*x-2


    elif x in arange(-math.pi/2,math.pi/2):
        y=(2/math.pi)*x


    elif x in arange(math.pi/2,math.pi):
        y=(-2/math.pi)*x+2

    return y
</code></pre>

<p>The 'in' keyword only checks if the searched element lies in the list. Here, your list contains only values in the step of 1. Perhaps the value of x is not an integral step. Hence, the corrected function would be:</p>

<pre><code>def f(x):

    y=x

    if x&gt;-math.pi and x&lt;-math.pi/2:
        y=(-2/math.pi)*x-2


    elif x&gt;-math.pi/2 and x&lt;math.pi/2:
        y=(2/math.pi)*x


    elif x&gt;math.pi/2 and x&lt;math.pi:
        y=(-2/math.pi)*x+2

    return y
</code></pre>

python function