Python if and elif not working, giving error
<p>I'm new in Python and doing an online tutorial. I have an assignment that I can not accomplish. My problem is that when I run this code, the <code>minimum</code> variable stays the same to <code>None</code> and does not record the new value input.</p>

<pre><code>maximum = None
minimum = None
while True:
    try:
        num2 = raw_input('Type here ')
        if num2 == 'done':break
        else:
            num = int(num2)
            if num &lt;= minimum:
                minimum = num
                print minimum
            elif num &gt;= maximum:
                maximum = num
                print maximum


    except:
        print 'Invalid Entry'


print 'Maximum is %d' % maximum
print 'Minimum is %d' % minimum
</code></pre>

<p>Your problem is that your are checking if <code>(some number) &lt;= None</code> You cannot compare numbers with <code>None</code>. Instead, <code>minimum=float("inf")</code> and <code>maximum=float("-inf")</code> would set minimum to infinity, and maximum to negative infinity. That way, the first number entered would be less than infinity, setting it to <code>minimum</code>, and greater than negative infinity (setting it to <code>maximum</code>). Note that <code>elif maximum &gt;= num</code> would need to be changed to <code>if maximum &gt;= num</code> (to handle the first entered number).</p>

python python-2.7 if-statement