title: How to stop Python while I key in a value that indicates "break"
body: <p>in the python code below, the desired output is to find the max and min from all of the key-in values (via input function) and when I key in &quot;done&quot;, it stops (meaning that there will be no pop-up anymore), while other non-integer strings will print &quot;Invalid output&quot;.</p>
  <p>However, even if I key in &quot;done&quot;, the pop-up still appears and it never ends, what is the problem of my code?</p>
  <pre><code>lar = None
  smal = None
  while True:
     try:
        num = int(input(&quot;Enter a number:&quot;))
     except:
        if num == &quot;done&quot;:
           break
        else:
           print(&quot;Invalid input&quot;)
     if lar is None:
        lar = num
     elif lar &lt;= num:
        lar = num
     if smal is None:
        smal = num
     elif smal &gt;= num:
        smal = num
  print(&quot;Maximum is&quot;, lar)
  print(&quot;Minimum is&quot;, smal)
  </code></pre>