SHARE
TWEET

Untitled

a guest Jun 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def eg_fr(n, d):
  2.     ls = []
  3.     ls_str = []
  4.     fraction = n / d
  5.     total = 0
  6.     for i in range(1, 1000):
  7.         ls.append((1/i, str(1) + '/' + str(i)))
  8.     for i in ls:
  9.     while i[0] + total <= fraction:
  10.         ls_str.append(i[1])
  11.         total += i[0]
  12.         if total >= fraction:
  13.             break
  14.     print('%s/%s = ' % (n, d), end='')
  15.     for i in range(len(ls_str) - 1):
  16.         print('', ls_str[i], '+ ', end='')
  17.     print(ls_str[-1], end='')
  18.     return ls_str
  19.  
  20.  
  21. if __name__ == '__main__':
  22. eg_fr(7, 133)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top