Less accurate fractions when rounding in Python 2.7
<p>Hi all I am very new to python and this is my first project. I am creating a calculator that when I enter the perimeter of a circle it will calculate the diameter for me. Such as handlebars on a motorcycle without taking the grips off. </p>

<p>I got it to work but I really need it to be less accurate like maybe round to the nearest 1/8. If I type 2.75 it works perfect but if I type 2.76 its give insane fractions. I would still like it to read 7/8 until its more then half way to 1.0</p>

<p>Here is what I have so far any help you can offer would be great. </p>

<pre><code>from fractions import Fraction

print "Do you wish to calculate the Diameter or Radius from a perimeter measurement? Type 'd' or 'r'"
var = raw_input("Please type 'd' or 'r'")


if var == 'd':
    print "Now type the perimeter measurement for the diameter you would like calculate."
    cir = float(raw_input())
    answer = cir/3.1415926535
    rnd = round(answer, 3 )
    frac = Fraction(rnd).limit_denominator()
    print rnd
    print "The diameter of a %s perimeter is" % cir, frac
elif var == 'r':
    print "Now type the perimeter measurement for the Radius you would like to calculate."
    cir = float(raw_input())
    answer = cir/3.1415926535/2
    print "The Radius of a %s perimeter is" % cir, answer 
else:
    print "Error: You did not type 'd' or 'r' Please run again"
</code></pre>