#Calculate the value of resistor
print '%s' %("Refer to the figure 1.52")
print '%s' %("Hold the resistor as shown in the figure such that tolerance is on your extreme right.")
print '%s' %("Now the value of the resistor is equal to")
print '%s' %(" Red Black Blue Gold")
print '%s' %(" 2 0 6 (+/-)5%")
red=2. #red value
blk=0 #black value
blu=6. #blue value
gld=5. #gold value
value_res=(red*10.+blk)*10.**blu #value of resistor
print '%s %.0f %s %.0f' %("\n The value of resistor is",value_res,"ohm (+/-)",gld)
per_val=0.05*value_res
pos_value_res=value_res+per_val #positive range of resistor
neg_value_res=value_res-per_val #negative range of resistor
print '%s %.0f %s %.0f %s ' %("\n The value of resistor is",neg_value_res*1e-6," Mohm and",pos_value_res*1e-6,"Mohm")
#Calculate the value of the resistor
print '%s' %("With the help of colour coding table, one finds")
print '%s' %(" 1st_Band 2nd_Band 3rd_Band 4th_Band")
print(" Yellow Violet Orange Gold")
print '%s' %(" 4 7 10**3 (+/-)5%")
yel=4. #yellow value
vio=7. #violet value
org=1e3 #orange value
gld=5. #gold value in %
val_res=(yel*10.+vio)*org
print '%s %.2f %s %.0f' %("\n The value of resistor is",val_res*1e-3,"kohm (+/-)",gld)
gld_ab=0.05 #absolute gold value
per_val=gld_ab*val_res
print '%s %.0f %s'%("\n Now, 5%% of 47k_ohm =",per_val, "ohm")
range_high=val_res+per_val #higher range
range_low=val_res-per_val #lower range
print'%s %.2f %s %.2f %s %.2f %s %.2f %s'%("\n\n Thus resistance should be within the range",val_res*1e-3, "kohm(+/-)",per_val*1e-3 ,"Kohm\n or between",range_low*1e-3 ,"kohm and",range_high*1e-3, "kohm")
#Calculate the value of the resistor
print '%s' %("The specification of the resistor from the color coding table is as follows")
print '%s' %(" 1st_Band 2nd_Band 3rd_Band 4th_Band")
print '%s' %(" Gray Blue Gold Silver")
print '%s' %(" 8 6 10**(-1) (+/-)10%")
gray=8. #gray value
blu=6. #blue value
gld=10.**-1 #gold value
sil=10. #silver value in %
val_res=(gray*10.+blu)*gld
print '%s %.2f %s %.2f' %("\n The value of resistor is",val_res, "ohm (+/-)",sil)
sil_ab=0.1 #absolute gold value
per_val=sil_ab*val_res
print '%s %.2f %s' %("\n Now, 10%% of 8.6 ohm =",per_val," ohm")
range_high=val_res+per_val #higher range
range_low=val_res-per_val #lower range
print '%s %.2f %s %.2f %s %.2f %s %.2f %s' %("\n\n Obviously resistance should lie within the range",val_res,"ohm(+/-)",per_val,"ohm\n or between",range_high,"ohm and",range_low,"ohm")
#Calculate the load voltage and load current
print '%s' %("Refer to the figure 1.53")
Vs=2. #supply voltage in V
Rs=1. #resistance in ohm
Is=Vs/Rs
print '%s %.2f %s' %("\n Current Is =",Is," A \n")
print '%s' %(" Internal resistance remains the same but is now connected in parralel with the current sourceIS,as shown in Figure 1.51(a)")
print '%s' %(" Now,we connect a load resistance R_L=1 ohm across the terminals of two representations ,and find I_L and V_L. From Figure 1.54(b) and using the current-divider concept,one obtains")
RL=1. #load resistance in ohm
IL=Is*(Rs/(Rs+RL)) #load current using current-divider
VL=IL*RL #load voltage
print '%s %.0f %s' %("\n Load voltage =",VL,"V")
print '%s %.0f %s' %("\n Load current =",IL,"A \n")
print '%s' %("From equation 53(b),using the voltage-divider concept,one obtains")
VD_vl=Vs*(RL/(RL+Rs)) #load voltage using voltage divider
VD_il=VL/RL #load current
print '%s %.0f %s' %("\n Load voltage =",VD_vl,"V")
print '%s %.0f %s' %("\n Load current =",VD_il,"A \n")
#Calculate the percentage variation in current, current for two extreme values R_L
print '%s' %("Refer to the figure 1.55")
print '%s' %("(a) R_L varies from 1 ohm to 10 ohm.")
print '%s' %("Currents for two extreme values of R_L are")
Vs=10. #supply voltage
RL1=1. #resistance RL1
Rs=100. #source resistance
IL1=(Vs/(RL1+Rs))
RL2=10.
IL2=(Vs/(RL2+Rs))
per_var_cur=((IL1-IL2)/IL1)*100.
print '%s %.2f %s' %("\n Percentage variation in current =",per_var_cur,"\n")#answer in the text book took a .3 decimal round off value
print '%s' %(" Now,load voltage for the two extreme values of R_L are")
VL1=IL1*RL1
VL2=IL2*RL2
per_var_vol=((VL2-VL1)/VL2)*100.
print '%s %.2f %s' %("\n Percentage variation in current =",per_var_vol,"\n")
print '%s' %("(b) R_L varies from 1 k-ohm to 10 k-ohm(Figure 1.55(b))")
print '%s' %("Currents for the two extreme values R_L are")
RL11=1000.
IL11=(Vs/(RL11+Rs))
RL22=10000.
IL22=(Vs/(RL22+Rs)) #mistake in book value
per_var_cur11=((IL11-IL22)/IL11)*100.
print '%s %.2f %s' %("\n Percentage variation in current =",per_var_cur11,"\n") #mistake in book value