title: How to check if a input is in binary format(1 and 0)?
body: <p>I have made a program however I wanted to add an exception if the user inputs is not in a binary format. I have tried many times adding exceptions but I can't seem to get it to work. The below is the program code. I would appreciate if someone could help.</p>
  
  <pre><code>import time
  error=True
  n=0
  while n!=1:
      print"***Welcome to the Bin2Dec Converter.***\n"
      while error:
          try:
              bin2dec =raw_input("Please enter a binary number: ")
              error=False
          except NameError: 
              print"Enter a Binary number. Please try again.\n"
              time.sleep(0.5)
          except SyntaxError: 
              print"Enter a Binary number. Please try again.\n"
              time.sleep(0.5)
  
  
          #converts bin2dec
          decnum = 0 
          for i in bin2dec: 
              decnum = decnum * 2 + int(i)
              time.sleep(0.25)
          print decnum, "&lt;&lt;This is your answer.\n" #prints output
  </code></pre>