from numpy import sqrt
from __future__ import division
To=12.6 #width of output pulse
Ti=0.3 #width of input pulse
l=1.2 #length of measurement
Pulse_dispersion = sqrt(To**2 - Ti**2) #computing pulse dispersion
PDKM=Pulse_dispersion/l #computing pulse dispersion per Kilometer
BW=0.44/PDKM #computing optical bandwidth
BW=BW*1000
print "Pulse broadning is %.1f ns/km.\nOptical bandwidth is %.1f MHz.Km." %(PDKM,BW)
from numpy import log10
V2=12
V1=2.5
L2=3
L1=0.004
alpha_dB = 10* log10(V2/V1)/(L2-L1)
un = 0.2/(L2-L1)
print "Attenuation is %.2f dB/km\nUncertainity +/- %.3f dB." %(alpha_dB,un)
#answer for attenuation in the book is wrong.