ThinkStats (2)

昨晩の続き、というか (ry
演習問題 1-3-3 ですが birthord のドキュメントが以下。

第一子と第二子は値が 1 または 2 というのが分かります。
また、その数値は (+ 4413 2874) というのが分かります。
実装的には以下らしいのですが、commit を作って 1-3-2 のナニを残すかどうか迷っています。

# -*- coding: utf-8 -*-

import survey

table = survey.Pregnancies()
table.ReadRecords()
print u' 妊娠レコードの総数 : ', len(table.records)

outcome = 0
for i in table.records:
#    if i.outcome == 1:
#        outcome += i.outcome
    if i.birthord == 1:
        outcome += 1
    elif i.birthord == 2:
        outcome += 1

print u' 生児出生の第一子と第二子の総数:', outcome

もっとアレな書き方があるのだろうな。

つうか

python の条件式な論理和は単純に or で良いらしい。以下でも OK なのか。

    if i.birthord == 1 or i.birthord == 2:
        outcome += 1

ちなみに

    if i.birthord == 1 or 2:
        outcome += 1

は NG でした。いやはや。
さ、仕事しよ。