While doing some coding challenges I ran across a very strange language quirk. The program I was writing was a lowest number finder. So basically you inputted a list of numbers and the program returned the lowest number. All went well for a while, like I said its a rather basic program, but when I started to input 2 or 3 digit numbers, the Boolean logic seemed to break down. Out of a list of 2 digit and 1 digit numbers like:
x = [10, 5, 10]
the program would return 10 as the lowest number. But in a regular 1 digit list the correct lowest value would be returned. So eventually I figured out that the bug was because I forgot to convert the string type to an integer type and once that was fixed the program ran flawlessly. But that still leads to an interesting question, why did Python believe that "10" was less than "5" but "9" was greater than "5"? To deliberately prove that Python believes that fact and it was not some outside factor in my program, I opened up a python interpreter and physically entered "10" < "5"
and the interpreter returned True
. Any ideas why this would be happening? Thank you in advance!