開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Think Python (Allen B. Downey (著)、 O'Reilly Media)のChapter 5.(Conditionals and Recursion)のExercises 5-3(No. 1257)を取り組んでみる。
Exercises 5-3(No. 1257)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def is_triangle(a, b, c):
if a <= b + c and b <= c + a and c <= a + b:
return 'Yes'
return 'No'
if __name__ == '__main__':
while True:
try:
print('input three stick lengths')
a = float(input())
if a <= 0:
break
b = float(input())
c = float(input())
except Exception as err:
print(err)
else:
print(is_triangle(a, b, c))
入出力結果(Terminal, IPython)
$ ./sample3.py input three stick lengths 1 1 1 Yes input three stick lengths 1 1 2 Yes input three stick lengths 1 1 3 No input three stick lengths 1 3 1 No input three stick lengths 3 1 1 No input three stick lengths 1 2 3 Yes input three stick lengths 1 2 4 No input three stick lengths 2 4 1 No input three stick lengths 4 1 2 No input three stick lengths 1 4 2 No input three stick lengths 4 2 1 No input three stick lengths 2 1 4 No input three stick lengths 0 $
0 コメント:
コメントを投稿