code: def parse(text):
          
          try:
              return int(text)
          except ValueError:
              try:
                  amount = float(text)
                  assert not isnan(amount) and not isinf(amount)
                  return amount
              except (ValueError, AssertionError):
                  return None
docs: Try to parse into a number.
  
          Return:
              the number (int or float) if successful; otherwise None.