title: How to make a dynamic float variable which is first embedded in a user input?
body: <p>TL;DR - The variable <em>importFunc</em> as defined in the first block of code is supposed to be a user input function expressed in terms of <em>x</em>, another variable which is supposed to be manipulated later in the <em>for loop</em> in the second block of code. This doesn't work, resulting in a <em>TypeError</em>. How do I create a dynamic variable <em>x</em> such that I can manipulate <em>inputFunc</em> like in the <em>for loop</em>?</p>
  
  <p>I'm currently learning python as my first coding language (not counting excel). My current project is an attempt to make a Riemman Sum calculator, including right, left, and diagonal Riemann Sums. As shown below, it strives to take some user input function in terms of <em>x</em> and output a Riemann Sum given the user's selected criteria.</p>
  
  <pre><code>import math
  
  x = 0. #can be any arbitrary float
  
  """inputs"""
  inputFunc = input("Input a function in terms of x\n")
  
  inputStart = float(input("Input start of range: "))
  inputEnd = float(input("Input end of range: "))
  inputSum = float(input("Input number of total summations over range: "))
  
  inputChoice = input("Input type of Riemann approximation.\n[Left/Right/Diagonal]\n")
  </code></pre>
  
  <p>Right now, my current test for debugging is inputting "x ** 2." when making a user input for <em>inputFunc</em>. (Note that I'm currently only working with left Riemann Sums.) However, I get an error when executing the following code:</p>
  
  <pre><code>rangeStep = float((inputEnd - inputStart) / inputSum)
  
  def riemannCalc(function):
  
    sumTotal = 0.
  
    if inputChoice.lower() in setLRS: #setLRS = ["left", "l"] (described earlier in program)
      for j in calcRange(inputStart, inputEnd, rangeStep): #defined earlier in program - functionally identical to range function except it allows for floats
        x = j
        sumTotal += function * rangeStep
      print(sumTotal)
  
  riemannCalc(inputFunc)
  </code></pre>
  
  <p>I get <em>TypeError: can't multiply sequence by non-int of type 'float'</em> for the line <em>sumTotal += function * rangeStep</em>. When debugging, appending the first block of code with the following function...</p>
  
  <pre><code>print(inputFunc)
  </code></pre>
  
  <p>returns <em>x ** 2.</em>, the same as my user input (even though I had set <em>x = 0.</em> earlier in the first block).</p>
  
  <p>This leads me to my question: how can I create a user input or a dynamic variable <em>x</em> such that I can manipulate <em>x</em> when it is expressed in <em>inputFunc</em> (e.g. I set <em>inputFunc = x ** 2.</em> and set <em>x = 4.</em> to yield <em>16.0</em> in the end), especially in the <em>for loop</em>?</p>