My program isnt correctly comparing values in python -
i wrote code , it's supposed compare set of line values nominal value. user supposed input percentage value compare linevalue
nominal value. if linevalue
within percentage given nominal value pass true.
my programme homecoming true if linevalue
number nominal value. other values failures if within percentage user inputs. see error in code prevent numbers beingness registered true?
nominalvalue=470 print "nominal resistor value: " , nominalvalue linevalue = [470, 358, 324, 234, 687,460] user_input=raw_input("please come in tolerance %: ") if user_input.isdigit(): tolerance = int(user_input) if tolerance <=20 , 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 seriesinput in linevalue: if (percentagehigh*seriesinput) <= highnominal , (percentagelow*seriesinput) >= lownominal: print seriesinput,"pass" print percentagehigh*seriesinput else: print seriesinput,"fail" print percentagelow*seriesinput else: print "please come in value between 1-20" else: print "please come in number percent value"
you've computed highnominal , lownominal, want line:
if seriesinput <= highnominal , seriesinput >= lownominal:
or @greghewgill pointed out:
if lownominal <= seriesinput <= highnominal:
python
No comments:
Post a Comment