TypeError for Python program (string formatting with %d)
<p>My program: A Math Quiz that prompts a user for a choice of difficulty (Beginner, Intermediate, Advanced) and then generates five questions (with random #'s) depending on their choice.</p>

<p>It was working completely fine until I started adding the comments and doc strings (I apologize if it's hard to read with the mess, instructor requires an exorbitant amount of comments.)</p>

<p>I apologize in advance for the messiness of the code (the instructor wants an exorbitant amount of comments).</p>

<pre><code># Import randint so program can generate random numbers

from random import randint

'''
Set the variable choice equal to the users input for choosing which level
they want to do. Then, we created an if statement equal to beginner  
(for user's input).  The range is the amount of questions for that
particular type of problem (addition, multiplication, etc.)
n1 is a random number from the range 1 to 10, program picks two
The variable 'sum' is set to the value n1 plus n2
'''

choice = input("Choose Level: Beginner,Intermediate, or Advanced?").lower()
if choice == "beginner":
    correct = 0
    for i in range(2):
        n1 = randint(1, 10)
        n2 = randint(1, 10)

# Set variable 'ans' to the input "What is (n1) plus (n2)"
# %d = program generates a random number for the problem
# correct = correct + 1 -&gt; adds one point to the user's overall score
        ans = input("What's %d plus %d?" % (n1, n2))
        if int(ans) == sum:
            print("That's correct, well done!\n")
            correct = correct + 1
        else:
            print("No it's not correct.  The answer is %d.\n" % sum) ## &lt; Here is where I'm getting the error message.**   
    for i in range(3):
        n1 = randint(1, 10)
        n2 = randint(1, 10)
        difference = n1 - n2

        ans = input("What's %d minus %d?" % (n1, n2))
        if int(ans) == difference:
            print("That's correct, well done!\n")
            correct = correct + 1
        else:
            print("No, that's not correct.  The answer is %d.\n" % difference)

# This is where the program calculates the score, and tells the user
# "Well Done", "Need more practice" or "Ask teacher for help".
    if(correct/5 &gt;= 2/3):
        print("Well done!")
    elif(correct/5 &gt;= 1/3):
        print("You need more practice.")
    else:
        print("Contact the instructor.")
if choice == "intermediate":
    correct = 0
    for i in range(3):
        n1 = randint(1, 25)
        n2 = randint(1, 25)
        product = n1 * n2

        ans = input("What's %d times %d?" % (n1, n2))
        if int(ans) == product:
            print("That's correct, well done!\n")
            correct = correct + 1
        else:
            print("No, that's not correct.  The answer is %d.\n" % product)        
    for i in range(2):
        n1 = randint(1, 25)
        n2 = randint(1, 25)
        quotient = n1 / n2

# For this section, we had to use a float input type and 'round' so that
# the program will take in a decimal point, and tell the user to round.
        ans = float(input("What's %d divided by %d? (Round 2 decimal places)" \
                          % (n1, n2)))
        if round(ans, 2) == round(quotient, 2):
            print("That's correct, well done!\n")
            correct = correct + 1
        else:
            print("No, that's not correct.  The answer is %f.\n" % quotient)       
    if(correct/5 &gt;= 2/3):
        print("Well done!")
    elif(correct/5 &gt;= 1/3):
        print("You need more practice.")
    else:
        print("Contact the instructor.")

if choice == "advanced":
    correct = 0
    for i in range(3):
        n1 = randint(11, 20)
        n2 = randint(1, 10)
        modulus = n1 % n2
        ans = input("What's %d modulus %d?" % (n1, n2))
        if int(ans) == modulus:
            print("That's correct, well done!\n")
        else:
            print("No, that's not correct.  The answer is %d.\n" % modulus)
    for i in range(2):
        n1 = randint(1, 10)
        n2 = randint(1, 10)
        exponent = n1 ** n2

        ans = input("What's %d to the power of %d? \
                     Don't need commas for answers)" % (n1, n2))
        if int(ans) == exponent:
            print("That's correct, well done!\n")
        else:
            print("No, that's not correct.  The answer is %d.\n" % exponent)
    if(correct/5 &gt;= 2/3):
        print("Well done!")
    elif(correct/5 &gt;= 1/3):
        print("You need more practice.")
    else:
        print("Contact the instructor.")
</code></pre>

<p>I'm getting this type error (on the first else print statement):</p>

<p><a href="http://i.stack.imgur.com/KwJpK.png" rel="nofollow"><img src="http://i.stack.imgur.com/KwJpK.png" alt="enter image description here"></a></p>

<p>I'm not sure if I messed something up when I added the comments, but I can't seem to figure out what it is.</p>

<p>You need to change some values.</p>

<p>In line</p>

<pre><code>ans = input("What's %d plus %d?" % (n1, n2))
</code></pre>

<p>Add</p>

<pre><code>result = n1 + n2
if int(ans) == result:
    print("That's correct, well done!\n")
        correct = correct + 1
    else:
        print("No it's not correct.  The answer is %d.\n" % result) # Here is where I'm getting the error message.**

...
...
</code></pre>

python typeerror modulus