t498.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. print "\nintegers"
  2. print pow(0, 0)
  3. print pow(0, 3)
  4. print pow(12, 0)
  5. print pow(2, 3)
  6. print pow(-2, 3)
  7. print pow(2, -3)
  8. print pow(-2, -3)
  9. print pow(4, 5, 3)
  10. print pow(-4, 5, 3)
  11. print pow(-4, 5, -3)
  12. print "\nlong integers"
  13. print pow(0L, 0L)
  14. print pow(0L, 3L)
  15. print pow(12L, 0L)
  16. print pow(2L, 3L)
  17. print pow(-2L, 3L)
  18. print pow(2L, -3L)
  19. print pow(-2L, -3L)
  20. print pow(4L, 5L, 3L)
  21. print pow(-4L, 5L, 3L)
  22. print pow(-4L, 5L, -3L)
  23. print "\nfloating point"
  24. print pow(0.0, 0.0)
  25. print pow(0.0, 3.1)
  26. print pow(12.0, 0.0)
  27. print pow(2.5, 3.7)
  28. print "\nintegers and long integers"
  29. print pow(2L, 3), type(pow(2L, 3))
  30. print pow(-2, 3L), type(pow(-2, 3L))
  31. print pow(2L, -3), type(pow(2L, -3))
  32. print pow(-2, -3L), type(pow(-2, -3L))
  33. print pow(2, 3, 5L), type(pow(2, 3, 5L))
  34. print pow(2, 3L, 5), type(pow(2, 3L, 5))
  35. print "\nintegers and floating point"
  36. print pow(2.5, 3), type(pow(2.5, 3))
  37. print pow(2, 3.5), type(pow(2, 3.5))
  38. print pow(2.5, -3), type(pow(2.5, -3))
  39. print pow(2, -3.5), type(pow(2, -3.5))
  40. print "\nfloating point and long integers"
  41. print pow(2.5, 3L), type(pow(2.5, 3L))
  42. print pow(2L, 3.5), type(pow(2L, 3.5))
  43. print pow(2.5, -3L), type(pow(2.5, -3L))
  44. print pow(2L, -3.5), type(pow(2L, -3.5))
  45. print "\nERROR CHECKING:"
  46. try:
  47. print pow([1, 2], '34')
  48. print "you shouldn't see this"
  49. except TypeError as e:
  50. print e
  51. try:
  52. print pow([1, 2], '34', 5)
  53. print "you shouldn't see this"
  54. except TypeError as e:
  55. print e
  56. try:
  57. print pow(-2.5, 3.7)
  58. print "you shouldn't see this"
  59. except ValueError as e:
  60. print e
  61. try:
  62. print pow(4.0, 5.0, 3)
  63. print "you shouldn't see this"
  64. except TypeError as e:
  65. print e
  66. try:
  67. print pow(4, -3, 2)
  68. print "you shouldn't see this"
  69. except TypeError as e:
  70. print e