Why do I have to divide by $\pi$ in order to scale amplitude of sine frequency spectrum? Recently I found my old code to transform sine wave from time domain to frequency domain. Below I post simplified version of it.

from math import sin, pi
from matplotlib.pyplot import *
from pylab import zeros, fft

fs = 500
duration = 2 * pi
amplitude = 2
frequency = 25
values_in_time_domain = []

for t in range(int(duration * fs)):
    values_in_time_domain.append(amplitude * sin(frequency * t / fs))

subplot(2, 1, 1)
title('Sinus from 0 to 2 pi in time domain; A = 2, f = 25, fs = 500')
plot(values_in_time_domain)

transform = fft(values_in_time_domain)
transform_abs = [abs(x) for x in transform]
values_in_freq_domain = [transform_abs[f] / fs / pi for f in range(int(fs / 2)+1)]

subplot(2, 1, 2)
title('Above sinus in frequency domain')
plot(values_in_freq_domain)

show()


Why do I have to divide every element from transform_abs by pi in the following: transform_abs[f] / fs / pi?
I noticed I need to do it in order to have properly scaled $O_y$ axis.
The FFT should be divided by the number of elements in the vector.  You specified the vector length to be duration = int(2*pi*fs) which is a really weird way to defining the length, btw.  Thus, you need to divide by int(2*pi*fs).  Yes, you need to divide by a 2 as well, because the signal energy is distributed evenly between positive and negative frequencies.