title: Python 3: Verifying port number (integer between 1-65535)
body: <p>I'm new to Python and trying to verify if a given port number is valid or not.</p>
  
  <p><strong>1st Attempt</strong></p>
  
  <pre><code>PortNumber = input("Enter a port number: ")
  if PortNumber.isdigit() == True:
     print("This is a VALID port number.")
  else:
     print("This is NOT a valid port number.")
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>C:\&gt; python test.py
  Enter a port number: a
  This is NOT a valid port number.
  
  C:\&gt; python test.py
  Enter a port number: -1
  This is NOT a valid port number.
  
  C:\&gt; python test.py
  Enter a port number: 8
  This is a VALID port number.
  
  C:\&gt; python test.py
  Enter a port number: 88888
  This is a VALID port number.
  
  C:\&gt;
  </code></pre>
  
  <p>The only problem with this code is the port number has to be an integer between <code>1-65535</code>.</p>
  
  <p><strong>2nd attempt</strong></p>
  
  <pre><code>PortNumber = int(input("Enter a port number: "))
  if 1&lt;= PortNumber &lt;= 65535:
      print('This is a VALID port number.')
  else:
      print('This is NOT a valid port number.')
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>C:\&gt; python test2.py
  Enter a port number: 65535
  This is a VALID port number.
  
  C:\&gt; python test2.py
  Enter a port number: 65536
  This is NOT a valid port number.
  
  C:\&gt; python test2.py
  Enter a port number: -1
  This is NOT a valid port number.
  
  C:\&gt; python test2.py
  Enter a port number: a
  Traceback (most recent call last):
    File "test2.py", line 1, in &lt;module&gt;
      PortNumber = int(input("Enter a port number: "))
  ValueError: invalid literal for int() with base 10: 'a'
  
  C:\&gt;
  </code></pre>
  
  <p>I managed to filter out the numbers between <code>1-65535</code> in second code, however there is another problem with the <code>a</code> character.</p>
  
  <p>How can I combine both ideas in the code?</p>