Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 4(Working with Text)、4.7(Exercises) 9.を解いてみる。
4.7(Exercises) 9.
コード(BBEdit)
sample9.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def total_length(s1, s2): """ (str, str) -> int return the sum of the lengths of s1 and s2 >>> total_length('yes', 'no') 5 >>> total_length('yes', '') 3 >>> total_length('YES!!!!', 'Noooooo') 14 """ return len(s1 + s2) if __name__ == '__main__': for s1, s2 in [('yes', 'no'), ('yes', ''), ('YES!!!!', 'Noooooo')]: print(total_length(s1, s2))
入出力結果(Terminal, IPython)
$ ./sample9.py 5 3 14 $
0 コメント:
コメントを投稿