開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
退屈なことはPythonにやらせよう ―ノンプログラマーにもできる自動化処理プログラミング (Al Sweigart(著)、相川 愛三(翻訳)、オライリージャパン)の第I部(Pythonプログラミングの基礎)、4章(リスト)、4.10(演習プロジェクト)、4.10.1(カンマ付け)の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 def comma(words: list) -> str: ''' >>> comma(['apples', 'bananas', 'tofu', 'cats']) 'apples, bananas, tofu, and cats' ''' return ', '.join(words[:-1]) + ', and ' + words[-1] if __name__ == '__main__': import doctest doctest.testmod()
入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))
C:\Users\...> py -3 sample1.py Trying: comma(['apples', 'bananas', 'tofu', 'cats']) Expecting: 'apples, bananas, tofu, and cats' ok 1 items had no tests: __main__ 1 items passed all tests: 1 tests in __main__.comma 1 tests in 2 items. 1 passed and 0 failed. Test passed. C:\Users\...>
0 コメント:
コメントを投稿