If I enter a one-digit input or a three-digit number, the code works but if I enter a two digit number, the if statement fails and the else condition prevails.
tsReading = input(" Enter the " + Brand + " test strip reading: ")
if tsReading == "": tsReading = "0"
print(tsReading)
if ((tsReading < "400") and (tsReading >= "0")):
tsDose = GetDose(sReading)
print(tsReading + "-" + tsDose)
ValueFailed = False
else:
print("Enter valid sensor test strip Reading.")
I converted the variable to int along with the if statement comparison and it works as expected.
See if it fails for you...
If I enter a one-digit input or a three-digit number, the code works but if I enter a two digit number, the if statement fails and the else condition prevails.
tsReading = input(" Enter the " + Brand + " test strip reading: ")
if tsReading == "": tsReading = "0"
print(tsReading)
if ((tsReading < "400") and (tsReading >= "0")):
tsDose = GetDose(sReading)
print(tsReading + "-" + tsDose)
ValueFailed = False
else:
print("Enter valid sensor test strip Reading.")
I converted the variable to int along with the if statement comparison and it works as expected.
See if it fails for you...
I converted the variable to int along with the if statement|True
comparison and it works as expected.
"2">"10"
If I enter a one-digitinput or a three-digit number,
tsReading = input("Enter the " + Brand + " test
if tsReading == "":tsReading = "0"
print(tsReading)"400") and (tsReading >=
if ((tsReading <
tsDose =GetDose(sReading)
print(tsReading+ "-" + tsDose)
ValueFailed =False
else:valid sensor test strip
print("Enter
I converted the variable toint along with the if
See if it fails for you...
With all these suggestions on
how to fix it, no one seems to
answer why it fails only when
entering a two-digit number.
One and three work fine when
comparing with str values. It
is interesting that the
leading 0 on a two digit
worked. Still, one digit and
three digit work but not two.
False"5" < "400"
True"1" < "400"
True"30" < "400"
False"50" < "400"
With all these suggestions on
how to fix it, no one seems to
answer why it fails only when
entering a two-digit number.
One and three work fine when
comparing with str values. It
is interesting that the
leading 0 on a two digit
worked. Still, one digit and
three digit work but not two.
This is now more of a
curiosity as I did use the
integer comparisons.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 446 |
Nodes: | 16 (2 / 14) |
Uptime: | 19:50:51 |
Calls: | 9,234 |
Calls today: | 1 |
Files: | 13,496 |
Messages: | 6,063,305 |