How to pull discount rate from if statement
<p>I need to calculate the total purchase price of the books. The discount is determined by the amount of books purchased. Those are split within the if statements. How can I have my code fully work? I am currently getting this error message: </p>

<p><a href="http://i.stack.imgur.com/GyRhK.png" rel="nofollow"><img src="http://i.stack.imgur.com/GyRhK.png" alt="Error message that is displayed"></a></p>

<p>Here's my code:</p>

<pre><code>BOOK_PRICE = 100

def main():
    numBooks = int(input("Enter the number of books you will be purchasing: "))
    discountPrice(numBooks)
    subTotalPrice(numBooks)
    #I have a problem getting the returned subTotal price
    totalPrice(theSubTotalPrice,discountRate)

def subTotalPrice (numBooks):
    theSubTotalPrice = numBooks * BOOK_PRICE
    print("Your subTotal is: $ ",theSubTotalPrice)
    return theSubTotalPrice
def totalPrice (theSubTotalPrice):
    theTotalPrice = theSubTotalPrice * discountRate
    print("Your Total Price is: $ ", theTotalPrice)
def discountPrice (numBooks):
    if numBooks &lt;= 0 and numBooks &lt;= 9:
        print(" ")
        discountRate = .00
        return discountRate
    if numBooks &gt;= 10 and numBooks &lt;= 19:
        print("Since you are ordering",numBooks,"books you will receive a 20% discount!")
        #how do any of these discountRates get put back to call them in a different module?
        discountRate = .20
        return discountRate
    if numBooks &gt;= 20 and numBooks &lt;= 49:
        print("Since you are ordering",numBooks,"books you will receive a 30% discount!")
        discountRate = .30
        return discountRate
    if numBooks &gt;= 50 and numBooks &lt;= 99:
        print("Since you are ordering",numBooks,"books you will receive a 40% discount!")
        discountRate = .40
        return discountRate
    if numBooks &gt;= 100:
        print("Since you are ordering",numBooks,"books you will receive a 50% discount!")
        discountRate = .50
        return discountRate
main()
</code></pre>

<p>Your last function is currently written as</p>

<pre><code>def totalPrice(theTotalPrice):
</code></pre>

<p>but your argument should be</p>

<pre><code>def totalPrice(numBooks):
</code></pre>

<p>In fact, you appear to pass the correct argument to this function in <code>main</code>, it is just a mistake in the actual function definition.</p>

<p>In general, if you see errors like "(some variable) is not defined", ensure that the variable is in scope, by passing the correct function arguments.</p>

python if-statement module