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>Here is the edited code. The first error was that you were returning the values from the functions, but there was no variable being assigned to the return value. Variables created inside a function lives only inside the function. Study the code below and see what changes I made. Ask if you have questions. Also you had another bug. You have numBooks &lt;=0 as a condition. It should be numBooks >= 0. One last thing, thanks for the copy and paste instead of screenshot.</p>

<pre><code>BOOK_PRICE = 100

def main():
    numBooks = int(input("Enter the number of books you will be purchasing: "))
    discountRate = discountPrice(numBooks)
    theSubTotalPrice = 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, discountRate):
    totalDiscount = theSubTotalPrice * discountRate
    theTotalPrice = theSubTotalPrice - totalDiscount
    print("Your Discount is: $ ", totalDiscount)
    print("Your Total Price is: $ ", theTotalPrice)
def discountPrice (numBooks):
    if numBooks &gt;= 0 and numBooks &lt;= 9:
        print(" ")
        discountRate = 0.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>Here is what I get when I ran it with various inputs:</p>

<pre><code>&gt;&gt;&gt; 
===== RESTART: C:\Users\Joe\Desktop\scripts\Stack_overflow\book_price.py =====
Enter the number of books you will be purchasing: 9

Your subTotal is: $  900
Your Total Price is: $  0.0
&gt;&gt;&gt; 
===== RESTART: C:\Users\Joe\Desktop\scripts\Stack_overflow\book_price.py =====
Enter the number of books you will be purchasing: 9

Your subTotal is: $  900
Your Total Price is: $  0.0
&gt;&gt;&gt; 
===== RESTART: C:\Users\Joe\Desktop\scripts\Stack_overflow\book_price.py =====
Enter the number of books you will be purchasing: 19
Since you are ordering 19 books you will receive a 20% discount!
# I need to take these two values and subtract them. 1900(subtotal) - 380 (discountprice)
Your subTotal is: $  1900
Your Total Price is: $  380.0
&gt;&gt;&gt; 
===== RESTART: C:\Users\Joe\Desktop\scripts\Stack_overflow\book_price.py =====
Enter the number of books you will be purchasing: 50
Since you are ordering 50 books you will receive a 40% discount!
Your subTotal is: $  5000
Your Total Price is: $  2000.0
&gt;&gt;&gt; 
</code></pre>

python if-statement module