[code.view]

[top] / python / PyMOTW / math / math_pow.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Exponentiation
     """
     #end_pymotw_header
     
     import math
     
     for x, y in [
         # Typical uses
         (2, 3),
         (2.1, 3.2),
     
         # Always 1
         (1.0, 5),
         (2.0, 0),
     
         # Not-a-number
         (2, float('nan')),
     
         # Roots
         (9.0, 0.5),
         (27.0, 1.0/3),
         ]:
         print '{:5.1f} ** {:5.3f} = {:6.3f}'.format(x, y, math.pow(x, y))
     

[top] / python / PyMOTW / math / math_pow.py

contact | logmethods.com