開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs(Text Editor)
- プログラミング言語: Python
初めてのコンピュータサイエンス(Jennifer Campbell、Paul Gries、Jason Montojo、Greg Wilson(著)長尾 高弘(翻訳))の4章(モジュール)の4.8(練習問題)を解いてみる。
1, 2, 3, 4.
入出力結果(Terminal)
$ python
Python 3.3.0 (default, Sep 29 2012, 08:16:08)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> help(math)
>>> math.fabs(round(-4.3))
4.0
>>> math.ceil(math.sin(34.5))
1
>>> help(math.ceil)
>>> math.sin(34.5)
0.057487478104924564
>>> import calendar
>>> help(calendar.isleap)
>>> calendar.isleap(2013)
False
>>> calendar.isleap(2014)
False
>>> calendar.isleap(2015)
False
>>> calendar.isleap(2016)
True
>>> help(calendar.leapdays)
>>> calendar.leapdays(2000, 2051)
13
>>> calendar.weekday(2016, 7, 29)
4
>>> calendar.weekday(2013, 4, 4)
3
>>> "boolean".upper()
'BOOLEAN'
>>> s="CO2 H2O"
>>> s.find("2")
2
>>> s.find("2", 3)
5
>>> help(str)
>>> "Boolean"[0].islower()
False
>>> "MoNDaY".lower().capitalize()
'Monday'
>>> " Monday".strip()
'Monday'
>>> help(str)
>>> " Monday".lstrip()
'Monday'
>>> "{0:6f}".format(math.sqrt(8))
'2.828427'
>>> quit()
$
5.
標準ライブラリに含まれていないモジュールが必要なときは、PyPI - the Python Package Index / Python Package Indexで探せばいい。pipを使えばsearchで検索できたり、installでインストールできたり便利。
0 コメント:
コメントを投稿