If statements with undefined variable
<p>I'm not sure what I'm doing wrong I tried to define "if the answer was <code>'Y'</code> Then <code>premium_membership=true</code>" but I keep getting this error. The beginning is as far as I get when I run the code and the second is my code.</p>

<pre><code>What is your name? John Smith 
How many books are you purchasing today? 5
Are you apart of our membership program? Enter Y for yes or N for No. N
Would you like to join our membership program for $4.95? Enter Y for yes or N for no. N
Thank you for your interest, and thanks for shopping with us!

John Smith 
The customer is purchasing 5.0 books
Traceback (most recent call last):
    File , line 41, in &lt;module&gt;
    if premium_member==True:
    NameError: name 'premium_member' is not defined
&gt;&gt;&gt; 
</code></pre>

<hr>

<pre><code>#ask what customer's name is
customer_name=input("What is your name?")

#ask customer how many books they are purchasing
#define answer as float so you can multiply by price later
books_purchased=float(input("How many books are you purchasing today?"))

#ask customer if they are a member
membership=input("Are you apart of our membership program? Enter Y for yes or N for No.")

#determine if and print if member or not
if membership =='Y':
    premium_member=True
else:
    join=input("Would you like to join our membership program for $4.95? Enter Y for yes or N for no.")

#define join
if join =='Y':
    print("Thank you for joining our Membership Program!")

else:
    print("Thank you for your interest, and thanks for shopping with us!")

#print name
print("\n",customer_name)

#print number of books purchased
print("The customer is purchasing", books_purchased, "books")

#determine if they customer is premium 
if premium_member==True:
    print("Premium Member")
else:
    print("Regular Member")       

#determine if customer gets any free books
if premium_member==True:
    if book_purchased&gt;9:
        print("Congratulations you get two books for free!")
        total_books=book_purchased+2
    else:
        if book_purchased &gt;6 and book_purchased&lt;=9:
            print("Congratulations you get one book for free!")
            total_books=books_purchased+1
        else:
            total_books=books_purchased
else:
    if books_purchased&gt;12:
            print("Congratulations you get two books for free!")
            total_books=book_purchased+2
    else:
        if books_purchased &gt;8 and books_purchased &lt;=12:
            print("Congratulations you get one book for free!")
            total_books=book_purchased+1
        else:
            total_books=books_purchased
</code></pre>

<p>In this section of code</p>

<pre><code>if membership =='Y':
    premium_member=True
else:
    join=input("Would you like to join our membership program for $4.95? Enter Y for yes or N for no.")
</code></pre>

<p>you're assigning <code>premium_member=True</code> in the case that <code>membership</code> is equal to <code>'Y'</code> but in the case that it's not (the <code>else</code> branch) you aren't assigning a value at all, meaning that the variable will be undefined. You should add the line <code>premium_member=False</code> to the <code>else</code> branch.</p>

<pre><code>if membership =='Y':
    premium_member=True
else:
    premium_member=False
    join=input("Would you like to join our membership program for $4.95? Enter Y for yes or N for no.")
</code></pre>

python python-3.x