Question on if, while, for.... Figured it out..

Fred c at tech.usd253.org
Mon Feb 11 12:01:48 EST 2002


OK, I figured it out (one other way at least).

-------------------

num = input("Enter the numerator: ")
den = input("Enter the denominator: ")
test = 0

if num > den:		#Test for improper fraction.
    i = num/den		#This will only return the whole part. 
    j = num%den		#This will return only the remainder.

    if j != 0:
        for i in range(9,0,-1):
            if num%i == 0 and den%i ==0 and test != 1:
                a = j/i
                b = den/i
                print "You entered an improper fraction, simplified it
is: %d %d/%d" % (i,a,b),
                test = 1
    else:
        print "You entered an improper fraction, simplified it is: %d"
% (i)
	
        

else:
    for i in range(9,0,-1):
        if num%i == 0 and den%i ==0 and test != 1:
            a = num/i
            b = den/i
            print "The fraction you entered is %d/%d in lowest terms."
% (a,b),
            test = 1



More information about the Python-list mailing list