Python 2.7: %d, %s, and float()
<p>I am attempting to teach myself a little coding through the "learn python the hard way" book and am struggling with %d / %s / %r when tying to display a floating point number.  How do you properly pass a floating point number with a format character?  First I tried %d but that made my answers display as integers.... I had some success with %r, but I was under the assumption that was usually reserved for debugging?  I figured out for division in python 2.x you have to manually float the denominator for it to properly work for some reason.</p>

<p>Example code:</p>

<pre><code>def divide (a, b):
    print "WE DIVIDING %r and %r NOW" % (a, b)
    return a / float(b)
print "Input first number:"
first = float(raw_input("&gt;  "))
print "OK, now input second number:"
second = float(raw_input("&gt;  "))

ans = divide(first, second)
print "DONE: %r DIVIDED BY %r EQUALS %r, SWEET MATH BRO!" % (first, second, ans)
</code></pre>
