2019年3月15日金曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 2(Hello, Python)、Exercises 2、3の解答を求めてみる。

コード

Python 3

#!/usr/bin/env python3
def test2():
    '''
    >>> x = -17
    >>> +x
    -17
    '''
    pass


def test3():
    '''
    >>> temp = 24 # a    
    >>> temp = temp * 9 / 5 + 32 #b
    >>> temp
    75.2
    '''
    pass


if __name__ == '__main__':
    import doctest
    doctest.testmod()

入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))

C:\Users\...>py -3 sample2.py -v
Trying:
    x = -17
Expecting nothing
ok
Trying:
    +x
Expecting:
    -17
ok
Trying:
    temp = 24 # a    
Expecting nothing
ok
Trying:
    temp = temp * 9 / 5 + 32 #b
Expecting nothing
ok
Trying:
    temp
Expecting:
    75.2
ok
1 items had no tests:
    __main__
2 items passed all tests:
   2 tests in __main__.test2
   3 tests in __main__.test3
5 tests in 3 items.
5 passed and 0 failed.
Test passed.

C:\Users\...>

0 コメント:

コメントを投稿