Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #encoding:utf-8
- from operator import add, sub
- def a_plus_abs_b(a, b):
- """Return a+abs(b), but without calling abs.
- >>> a_plus_abs_b(2, 3)
- 5
- >>> a_plus_abs_b(2, -3)
- 5
- """
- if b < 0:
- f = sub
- else:
- f = add
- return f(a, b)
- if __name__ == "__main__":
- import doctest
- doctest.testmod(verbose=True)
Add Comment
Please, Sign In to add comment