title: Python - Return Either Float or Integer Depending on Calculated Value
body: <p>I'm new to Python and have been writing out simple programs to get acquainted with the language.</p>
  
  <p>What I am trying to determine is how to calculate output value types dynamically and return them accordingly.  The only way I can get the code to accurately output values is to hard code the casting of type float but i'd like to be able to have dynamic output. Any pointers in the right direction would be much appreciated!</p>
  
  <p>Sample Input/Output:</p>
  
  <ol>
  * Input = 0, Output = 32.0  (Desired Output: 32)
  </ol>
  
  <ol>
  * Input = 1, Output = 33.8
  </ol>
  
  <p>Code Example:</p>
  
  <pre><code># Definite functions
  def is_number(x):
      try:
          return int(x)
      except ValueError:
          try:
              return float(x)
          except ValueError:
              return False
  
  
  def calc_fahrenheit(x):
      try:
          return (is_number(x) * 9.0) / 5 + 32
      except:
          raise
  
  # Runtime Code
  celsius = raw_input("Enter Celsius Temperature: ")
  
  while(calc_fahrenheit(celsius) == False):
      celsius = raw_input("Please enter valid Celsuis Temperature: ")
  
  print calc_fahrenheit(celsius)
  </code></pre>