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>Basically, you're not giving your functions all the variables that they need. In <code>eligibleDiscounts</code> you reference a variable <code>totalPrice</code>. Where is that value being defined? Is it meant to be <code>BOOK_PRICE * numBooks</code>?</p>

<p>Similar thing in <code>totalPrice</code>. If you want it to know about <code>numBooks</code>, you need to pass <code>numBooks</code> in. </p>

<p>I think what you want to do is calculate the <code>totalPrice</code>, and pass that into <code>eligibleDiscount</code>. Then have <code>eligibleDiscount</code> return <code>discountRate</code>. I.e. end with <code>return discountRate</code>. Which should be defined under each <code>if</code>/<code>elif</code> statement. Not just the last one.</p>

<p>Then pass everything into <code>totalPrice</code>.</p>

python if-statement module