2014年9月14日日曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の8章(スタティックライブラリとダイナミックライブラリ: ホットスワップ可能なコード)、自分で考えてみよう(p.367)をpythonで考えてみる。

自分で考えてみよう(p.367)

コード(BBEdit, Emacs)

elliptical.py

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

import sys

sys.path.append('libs')

import hfcal

hfcal.display_calories(115.2, 11.3, 0.79)

libs/hfcal.py

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

def display_calories(weight, distance, coeff):
    print('体重:{0:3.2f}ポンド'.format(weight))
    print('距離:{0:3.2f}マイル'.format(distance))
    print('消費カロリー:{0:4.2f}カロリー'.format(coeff))

入出力結果(Terminal, IPython)

$ ./elliptical.py
体重:115.20ポンド
距離:11.30マイル
消費カロリー:0.79カロリー
$

0 コメント:

コメントを投稿