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 5(Making Choices)、5.6(Exercises) 7.を解いてみる。
5.6(Exercises) 7.
コード(BBEdit)
sample7.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
for population, land_area in [(a, b) for a in
[9000000, 10000000, 35000000, 40000000] for b in
[80000, 90000, 340000, 300000]]:
print('population = {0}, land_area = {1}'.format(population, land_area))
print('1.')
if population < 10000000:
print(population)
print('2.')
if 10000000 <= population <= 35000000:
print(population)
print('3.')
if population / land_area > 100:
print('Densely populated')
print('4.')
if population / land_area > 100:
print('Densely populated')
else:
print('Sparsely populated')
入出力結果(Terminal, IPython)
a$ ./sample7.py population = 9000000, land_area = 80000 1. 9000000 2. 3. Densely populated 4. Densely populated population = 9000000, land_area = 90000 1. 9000000 2. 3. 4. Sparsely populated population = 9000000, land_area = 340000 1. 9000000 2. 3. 4. Sparsely populated population = 9000000, land_area = 300000 1. 9000000 2. 3. 4. Sparsely populated population = 10000000, land_area = 80000 1. 2. 10000000 3. Densely populated 4. Densely populated population = 10000000, land_area = 90000 1. 2. 10000000 3. Densely populated 4. Densely populated population = 10000000, land_area = 340000 1. 2. 10000000 3. 4. Sparsely populated population = 10000000, land_area = 300000 1. 2. 10000000 3. 4. Sparsely populated population = 35000000, land_area = 80000 1. 2. 35000000 3. Densely populated 4. Densely populated population = 35000000, land_area = 90000 1. 2. 35000000 3. Densely populated 4. Densely populated population = 35000000, land_area = 340000 1. 2. 35000000 3. Densely populated 4. Densely populated population = 35000000, land_area = 300000 1. 2. 35000000 3. Densely populated 4. Densely populated population = 40000000, land_area = 80000 1. 2. 3. Densely populated 4. Densely populated population = 40000000, land_area = 90000 1. 2. 3. Densely populated 4. Densely populated population = 40000000, land_area = 340000 1. 2. 3. Densely populated 4. Densely populated population = 40000000, land_area = 300000 1. 2. 3. Densely populated 4. Densely populated $
0 コメント:
コメントを投稿