Advertisement
overexchange

code

May 25th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. def make_rational(num, den):
  2.     def dispatch(m):
  3.         if m == 0:
  4.             return num
  5.         elif m == 1:
  6.             return den
  7.         else:
  8.             print('Invalid input')
  9.     return dispatch
  10.  
  11. r1 = make_rational(1, 2)
  12. r2 = make_rational(3, 4)
  13. num = r1(0)
  14. den = r1(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement