Share your repls and programming experiences

← Back to all posts
Egyptian fractions
stephaneplancke (0)

This algorithm decomposes a fraction which is less than one as a sum of unit fractions.

Commentshotnewtop
ChezCoder (83)

um I think your supposed to un indent the last line to call the function???

def fraction(p,q):
  if p==0:
    print ('fini')
  else: 
    n=1
    k=p-q
    while k<0:
      n=n+1
      k=p*n-q
    print (n)
    p=p*n-q
    q=q*n

p = int(input('Please enter the numerator >>> '))
q = int(input('Please enter the denomenator >>> '))
fraction(p,q)

just copy and paste my code into your project :p

stephaneplancke (0)

@ChezCoder Hi! The function "fraction(p,q)" is actually used in the definition of the fraction(p,q) in a recursive way, so it needs to be indented the way I did.