from __future__ import division
Y=90
X=89
Error_absolute=Y-X
print 'Absolute Error =',round(Error_absolute,2)
Error_relative=(Y-X)*100/Y
print 'Relative Error = %0.2f %%'%Error_relative
Accuracy_relative=1-Error_relative
print 'Accuracy relative =',round(Accuracy_relative,2)
Accuracy_percentage=100*Accuracy_relative
print 'Accuracy = %0.2f %%'%Accuracy_percentage
S=98+100+102+98+100+100+104+104+105+97
n=10
Avg=S/n
P=1-abs((104-Avg)/Avg)
print "Precision for the 8th reading=%.2f"%(P)
V=10
I=20*10**-3
RI=50
R=(V/I)-RI
print "The value of Resistance=%.0f ohm"%(R)
dV=0.2
dI=1*10**-3
dRI=5
dR=(dV/I)+(V*dI/I**2)+(dRI)
print "Limiting error of resistance=%.0f ohm"%(dR)
R0=5
a=0.004
T=30
R=R0*(1+a*(T-20))
print "Resistance of the wire=%.1f ohm"%(R)
#Let (dR/dR0) =b (dR/da)=c (dR/dT)=d
b=(1+a*(T-20))
c=R0*(T-20)
d=R0*a
ur0=5*0.003
ua=0.004*0.01
ut=1
uR=(b**2*ur0**2+c**2*ua**2+d**2*ut**2)**0.5
print "Uncertanity in resistance=%.2f ohm"%(uR)
X_mean=(15+20+25+30+35+45)/6
print "The sample mean of the temperature=%.2f degree C"%(X_mean)
Y_mean=(1.9+1.93+1.97+2+2.01+2.01+1.94+1.95+1.97+2.02+2.02+2.04)/12*10**-6
print "The sample mean of the faliure=%.6f failures/hour"%(Y_mean)
print 'from these values we get'
a=1.80*10**-6
b=0.00226
print 'Y=1.80+0.00226x is the required least square line'
n=2
k=1
dof=n-k
chi_square=(3-5)**2/5+(7-5)**2/5
print 'Chi square value =',chi_square
print 'From the dof and chi square value we find P=0.22'
print 'Hence there are 22% chance that the distribution is just the result of random fluctuations and the coin may be unweighted'
X_mean=501*1/5
print "Assigned Value=%.1f V"%(X_mean)
sigma=((1/(5-1))*((100.2-X_mean)**2+(100.3-X_mean)**2+(100.2-X_mean)**2+(100.2-X_mean)**2+(100.1-X_mean)**2))**0.5
#print 'For 95% confidance level student factor t is 2.78'
t=2.78
n=5
Ur=t*sigma/(n**0.5)
print "Uncertanity=%.3f V"%(Ur)