title: Reducing Equation Loop
body: <p>I'm trying to create a loop where if the value of "X" is a whole number it divides it by 2 and that's the new value. Then if the new value is a whole number it divides by 2 or if it has a decimal it subtracts it by 0.5 and that becomes the new value. I want it to loop from "X" to >= 1.5</p>
  
  <p>I've tried a while/if/elif and I get close but when I change my "X" value from 217 to 218 the output isn't right.</p>
  
  <pre><code>def func():
      val = 217
      while val &gt;= 1.5:
          val = val/2
          print(val)
          if val is float:
              val = val-.5
              print(val)
          elif val is int:
              val = val/2
              print(val)
          else:
              val = val//2
              print(val)
  func()
  </code></pre>
  
  <p>When val = 217 this renders perfectly with the exception of it going to 0.0 instead of 1.5</p>
  
  <p>Also the else: val = val//2 seems off to me but this is the closest I've gotten to rending this code the way I want it to.</p>
  
  <p>Output:</p>
  
  <p>108.5
  54.0
  27.0
  13.0
  6.5
  3.0
  1.5
  0.0  &lt;--- don't get why this is here when the while loop states >= 1.5</p>
  
  <p>Now if you change the val to 218</p>
  
  <pre><code>def func():
      val = 218
      while val &gt;= 1.5:
          val = val/2
          print(val)
          if val is float:
              val = val-.5
              print(val)
          elif val is int:
              val = val/2
              print(val)
          else:
              val = val//2
              print(val)
  func()
  </code></pre>
  
  <p>Output:</p>
  
  <p>109.0
  54.0
  27.0
  13.0
  6.5
  3.0
  1.5
  0.0</p>
  
  <p>Kind of bugs out because 218/2 = 109 then 109/2 = 54.5</p>
  
  <p>Since I want the code to print out each new value I would want it to show each value as if you're typing each equation then hitting the equals sign. I want the output to look like this:</p>
  
  <p>Output:</p>
  
  <p>109.0 (/2)
  54.5 (-0.5)
  54.0 (/2)
  27.0 (/2)
  13.5 (-0.5)
  13.0 (/2)
  6.5 (-0.5)
  6.0 (/2)
  3.0 (-1.5)
  1.5 (>= 1.5)</p>
  
  <p>Output is coming out close to what I want but not exactly.</p>