I wrote this code and it's supposed to compare the set of line values with the nominal value. The user is supposed to input a percentage value that will compare the lineValue to the nominal value. If the lineValue is within the percentage given for the nominal value it will pass as true.
My program will only return true only if the lineValue number is exactly the nominal value. All other values are failures even if it is within the percentage that the user inputs. Does anyone see an error in my code that would prevent the numbers from being registered as true?
nominalValue=470
print "Nominal Resistor Value: " , nominalValue
lineValue = [470, 358, 324, 234, 687,460]
user_Input=raw_input("Please Enter a Tolerance %: ")
if user_Input.isdigit():
tolerance = int(user_Input)
if tolerance <=20 and tolerance >=1:
print "Tolerance Level:", user_Input
percentageHigh = (tolerance/100.0 + 1.00)
percentageLow = (1.00 - tolerance/100.0)
print percentageHigh
print percentageLow
highNominal = nominalValue*percentageHigh
lowNominal = nominalValue*percentageLow
print highNominal
print lowNominal
for seriesInput in lineValue:
if (percentageHigh*seriesInput) <= highNominal and (percentageLow*seriesInput) >= lowNominal:
print seriesInput,"Pass"
print percentageHigh*seriesInput
else:
print seriesInput,"Fail"
print percentageLow*seriesInput
else:
print "Please enter a value between 1-20"
else:
print "Please enter a number for a percent value"
1 <= tolerance <= 20means the same thing as you have written for checking the tolerance number.