開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs(Text Editor)
- プログラミング言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7)のII部(ビルトイノブジェクと)、5章(数値)の練習問題を解いてみる。
その他参考書籍
1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
print(2 * (3 + 4)) # 14
print(2 * 3 + 4) # 10
print(2 + 3 * 4) # 14
import math
print(math.sqrt(2))
print(pow(2, 4))
print(type(1 + 2.0 + 3)) # float型
f = 1.5
print(math.floor(f)) # 1 切り捨て
print(round(f)) # 2 丸め(四捨五入)
print(float(5)) # 5.0 整数を浮動小数点数に変換
n = 20
print(oct(n)) # '0o24' 8進数
print(hex(n)) # '0x14' 16進数
print(int('0o24', 8)) # 20
print(int('0x14', 16)) # 20
入出力結果(Terminal)
$ ./sample.py 14 10 14 1.4142135623730951 16 <class 'float'> 1 2 5.0 0o24 0x14 20 20 $
0 コメント:
コメントを投稿