title: How to compute a percentage increase/decrease multiplier in python without if statements
body: <p>I have a scenario in which the user enter a positive, 0, or negative value which represents a percentage increase, no change, or percentage decrease, respectively. Example: 2.5 means "increase by 2.5%",  -3 means "decrease by 3%". Let's call this user entered number U.</p>
  
  <p>I need to apply U to some number, X, in python... that is, apply the percentage increase/decrease specified in U to X to come up with the possibly altered value for X.</p>
  
  <p>I can see one way to do this is by examining U and come up with a multiplier that can be multiplied by X, such as </p>
  
  <pre><code>if U == 0:
     multiplier = 1
  elif U &gt; 0:
     multiplier = U/100.0 + 1
  else:
     multiplier = (100 - (U * -1.0))/100.0
  </code></pre>
  
  <p>And then I can arrive at the new value of X with:  X = X * multiplier.</p>
  
  <p>Finally, the challenging part: <em>Is there a way to come up with a multiplier without using multiple if statements as I've done above?</em>  </p>
  
  <p>The reason I ask is because I'm actually having to write a snippet of python code that has to be contained in one line (it is is going to be dynamically executed with exec()) and thus I can't have blocks.</p>
  
  <p>Any ideas on this would be greatly appreciated!
  Michael</p>