開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Python for Kids: A Playful Introduction to Programming (Jason R. Briggs (著) 、No Starch Press)のPart Ⅰ.(Learning to Program)、Chapter 6.(Going Loopy)、Programming Puzzles(No. 1474)を解いてみる。
Programming Puzzles(No. 1474)
コード(Emacs, BBEdit)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
print('#2: Even Numbers')
for x in range(2, 15):
if x % 2 == 0:
print(x)
for x in range(2, 15, 2):
print(x)
print('#3: My Five Favorite Ingredients')
ingredients = ['snails', 'leeches', 'gorilla belly-button lint',
'caterpillar eyebrows', 'centipede toes']
for i in range(len(ingredients)):
print('{0} {1}'.format(i + 1, ingredients[i]))
print('#4: Your Weight on the Moon')
weight = 50
for year in range(16):
print('{0:2} Earth wiehgt: {1:.2f} Moon weight: {2:.2f}'.format(
year, weight, weight * 0.165))
weight += 1
入出力結果(Terminal, IPython)
$ ./sample.py #2: Even Numbers 2 4 6 8 10 12 14 2 4 6 8 10 12 14 #3: My Five Favorite Ingredients 1 snails 2 leeches 3 gorilla belly-button lint 4 caterpillar eyebrows 5 centipede toes #4: Your Weight on the Moon 0 Earth wiehgt: 50.00 Moon weight: 8.25 1 Earth wiehgt: 51.00 Moon weight: 8.42 2 Earth wiehgt: 52.00 Moon weight: 8.58 3 Earth wiehgt: 53.00 Moon weight: 8.75 4 Earth wiehgt: 54.00 Moon weight: 8.91 5 Earth wiehgt: 55.00 Moon weight: 9.08 6 Earth wiehgt: 56.00 Moon weight: 9.24 7 Earth wiehgt: 57.00 Moon weight: 9.41 8 Earth wiehgt: 58.00 Moon weight: 9.57 9 Earth wiehgt: 59.00 Moon weight: 9.74 10 Earth wiehgt: 60.00 Moon weight: 9.90 11 Earth wiehgt: 61.00 Moon weight: 10.07 12 Earth wiehgt: 62.00 Moon weight: 10.23 13 Earth wiehgt: 63.00 Moon weight: 10.40 14 Earth wiehgt: 64.00 Moon weight: 10.56 15 Earth wiehgt: 65.00 Moon weight: 10.72 $
1 コメント :
Thanks for sharing such a nice blog.
Python Online Training
コメントを投稿