2014年7月24日木曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 5.(Numeric Types)、Test Your Knowledge: Quiz 4.を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 4.

コード(BBEdit)

sample6.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import math

for x in range(10):
    print(math.sqrt(x), end=' ')
print()

for x in range(10):
    print(x * x, end=' ')
print()

for x in range(10):
    print(x ** 2, end=' ')
print()

for x in range(10):
    print(pow(x, 2), end=' ')
print()

for x in range(10):
    print(math.pow(x, 2), end=' ')
print()

help(pow)
help(math.pow)

入出力結果(Terminal, IPython)

$ ./sample4.py 
0.0 1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979 2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 
0 1 4 9 16 25 36 49 64 81 
0 1 4 9 16 25 36 49 64 81 
0 1 4 9 16 25 36 49 64 81 
0.0 1.0 4.0 9.0 16.0 25.0 36.0 49.0 64.0 81.0 
Help on built-in function pow in module builtins:

pow(...)
    pow(x, y[, z]) -> number
    
    With two arguments, equivalent to x**y.  With three arguments,
    equivalent to (x**y) % z, but may be more efficient (e.g. for ints).

Help on built-in function pow in module math:

pow(...)
    pow(x, y)
    
    Return x**y (x to the power of y).

$

0 コメント:

コメントを投稿