The problem is that it raw_inputreturns a string (not a number), and for some odd historical reasons, the strings can be compared (for ordering) with any other kind of object by default, but the results are .... strange.
Python 2.6.5 (r265:79063, Oct 28 2010, 20:56:23)
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 < "2"
True
>>> 1 < "0"
True
>>> 1 < ""
True
>>>
Convert the result to an integer before comparing it:
c = int(raw_input("How many courses you have enrolled in this semester?:"))
source
share