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

Paul Rubin phr-n2002a at nightsong.com
Mon Feb 11 17:42:23 EST 2002


c at tech.usd253.org (Fred) writes:
> 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:...

Does this do what you really want, if the fraction entered is 8/12?



More information about the Python-list mailing list