Nov-12-2022, 07:19 AM
(This post was last modified: Nov-13-2022, 05:44 PM by deanhystad.)
The main problem with the code is that it doesn't compare numbers. It compares number strings. It doesn't use "val" anywhere.
You can verify by doing this:
Since you are comparing strings, this makes perfect sense and is True (ord("b") > ord("7")).
You can verify by doing this:
> python test.py enter a num 5 setting largest to 5 largest: 5 *********** setting smallest to 5 smallest: 5 *********** enter a num 1234567 setting smallest to 1234567 smallest: 1234567 ***********Numerically 1234567 is greater than 5, but as a string, "5" > "1", so "5" > "1234567".
Since you are comparing strings, this makes perfect sense and is True (ord("b") > ord("7")).
if "7" is None || "bob" > "7":If you compare "bob" and the number 7 you get a TypeError.