2014年12月24日水曜日

開発環境

Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 4(Py Crust: Code Structures)、Things to Do 4.9.を解いてみる。

Things to Do 4.9.

コード(BBEdit)

sample9.py

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

def get_odds():
    for n in range(10):
        if n % 2 != 0:
            yield n

i = 0            
for n in get_odds():
    i += 1
    if i == 3:
        print(n)            

入出力結果(Terminal, IPython)

$ ./sample9.py
5
$

0 コメント:

コメントを投稿