2013年2月24日日曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のIII部(ステートメント)のまとめ演習4.(プログラミを書き直す)を解いてみる。

その他参考書籍

4.(プログラミを書き直す)

コード(BBEdit)

sample.py

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

L = []
for x in range(7):
    L.append(2 ** x)
X = 2 ** 5
if X in L:
    print("at index {0}".format(L.index(X)))
else:
    print("{0} not found".format(X))

入出力結果(Terminal)

$ ./sample.py
at index 5
$

ちなみにJavaScriptの場合。

コード(BBEdit)

var a = [],
    x = Math.pow(2, 5),
    result = "",
    i, max;
for (i = 0, max = 7; i < max; i += 1) {
    a.push(Math.pow(2, i));
};
label:
{
    for (i = 0, max = a.length; i < max; i += 1) {
        if (a[i] === x) {
            result = "at index " + i;
            break label;
        }
    }
    result = x + " not found"
}
$('#pre0').text(result);










						

0 コメント:

コメントを投稿