Advertisement
rfmonk

decimal_operators.py

Jan 22nd, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # credit for this goes to the author
  4. # of The Python Standard Library by example
  5. # Jesse Noller, Python Core Developer and PSF Board Member
  6. # Book can be purchased on amazon, it is also
  7. # on the oreilly bookshelf and may be at your
  8. # library. I'm only reprinting the code example
  9. # here because I'm working on this stuff as a
  10. # student of the Python Programming language.
  11. # Thanks Jesse Noller for such a good book.
  12.  
  13. import decimal
  14.  
  15. a = decimal.Deciaml('5.1')
  16. b = decimal.Decimal('3.14')
  17. c = 4
  18. d = 3.14
  19.  
  20. print 'a    =', repr(a)
  21. print 'b    =', repr(b)
  22. print 'c    =', repr(c)
  23. print 'd    =', repr(d)
  24. print
  25.  
  26. print 'a + b =', a + b
  27. print 'a - b =', a - b
  28. print 'a * b =', a * b
  29. print 'a / b =', a / b
  30. print
  31.  
  32. print 'a + c =', a + c
  33. print 'a - c =', a - c
  34. print 'a * c =', a * c
  35. print 'a / c =', a / c
  36. print
  37.  
  38. print 'a + d =',
  39. try:
  40.     print a + d
  41. except TypeError, e:
  42.     print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement