2016年5月26日木曜日

開発環境

Think Python (Allen B. Downey (著)、 O'Reilly Media)のChapter 7.(Iteration)のExercises 7-2(No. 1686)を取り組んでみる。

Exercises 7-2(No. 1686)

コード(Emacs)

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

import math

def eval_loop():
    while True:
        result = input('>> ')
        if result == 'done':
            break
        try:
            print(eval(result))
        except Exception as err:
            print(err)
        
if __name__ == '__main__':
    eval_loop()

入出力結果(Terminal, IPython)

$ ./eval_loop.py
>> 1 + 2 * 3
7
>> math.sqrt(5)
2.23606797749979
>> type(math.pi)
<class 'float'>
>> done
$

0 コメント:

コメントを投稿