開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7)のⅡ部(ビルトインオブジェクト)、5章(数値)の練習問題、4.を解いてみる。
その他参考書籍
4.
コード(BBEdit)
module1.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- import math # 平方根はmathモジュールのsqrt # 平方はビルトイン関数のpowまたは** for n in range(1, 11): print('√{0} = {1}'.format(n, math.sqrt(n))) print('平方: {0} {1}'.format(pow(n, 2), n ** 2))
入出力結果(Terminal)
$ ./sample.py √1 = 1.0 平方: 1 1 √2 = 1.4142135623730951 平方: 4 4 √3 = 1.7320508075688772 平方: 9 9 √4 = 2.0 平方: 16 16 √5 = 2.23606797749979 平方: 25 25 √6 = 2.449489742783178 平方: 36 36 √7 = 2.6457513110645907 平方: 49 49 √8 = 2.8284271247461903 平方: 64 64 √9 = 3.0 平方: 81 81 √10 = 3.1622776601683795 平方: 100 100 $
0 コメント:
コメントを投稿