title: Python internal metric unit conversion function
body: <p>I'm trying to build a function to do internal metric conversion on a wavelength to frequency conversion program and have been having a hard time getting it to behave properly. It is super slow and will not assign the correct labels to the output. If anyone can help with either a different method of computing this or a reason on why this is happening and any fixes that I cond do that would be amazing!</p>
  
  <pre><code>def convert_SI_l(n):
  if n in range( int(1e-12),int(9e-11)):
      return n/0.000000000001, 'pm'
  else:
      if n in range(int(1e-10),int(9e-8)):
           return n/0.000000001 , 'nm'
      else:
          if n in range(int(1e-7),int(9e-5)):
              return n/0.000001, 'um'
          else:
              if n in range(int(1e-4),int(9e-3)):
                  return n/0.001, 'mm'
              else:
                  if n in range(int(0.01), int(0.99)):
                      return n/0.01, 'cm'
                  else:
                      if n in range(1,999):
                          return n/1000, 'm'
                      else:
                          if n in range(1000,299792459):
                              return n/1000, 'km'
                          else:
                              return n , 'm'
  
  def convert_SI_f(n):
      if n in range( 1,999):
          return n, 'Hz'
      else:
          if n in range(1000,999999):
               return n/1000 , 'kHz'
          else:
              if n in range(int(1e6),999999999):
                  return n/1e6, 'MHz'
              else:
                  if n in range(int(1e9),int(1e13)):
                      return n/1e9, 'GHz'
                  else:
                      return n, 'Hz'
  
  c=299792458
  
  i=input("Are we starting with a frequency or a wavelength? ( F / L ):  ")
  
  #Error statements
  if i.lower() == ("f"):
      True
  else:
      if not i.lower() == ("l"):
          print ("Error invalid input")
  
  #Cases 
  if i.lower() == ("f"):
      f = float(input("Please input frequency (in Hz):  "))
      size_l = c/f
      print(convert_SI_l(size_l))
  
  if i.lower() == ("l"):
      l = float(input("Please input wavelength (in meters):  "))
      size_f = ( l/c)
      print(convert_SI_f(size_f))
  </code></pre>