2014年8月16日土曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 7(Using Methods)、7.6(Exercises) 9, 10.を解いてみる。

7.6(Exercises) 9, 10.

コード(BBEdit)

sample9.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

season = 'summer'
print('I love {0}!'.format(season))
print('I love {0}!'.format(season))
print('I love {season}!'.format(season=season))

side1 = 3
side2 = 4
side3 = 5

print('The sides have lengths {}, {}, {}'.format(side1, side2, side3))
print('The sides have lengths {0}, {1}, {2}'.format(side1, side2, side3))
print('The sides have lengths {side1}, {side2}, {side3}'.format(
    side1=side1, side2=side2, side3=side3))

入出力結果(Terminal, IPython)

$ ./sample9.py
I love summer!
I love summer!
I love summer!
The sides have lengths 3, 4, 5
The sides have lengths 3, 4, 5
The sides have lengths 3, 4, 5
$

0 コメント:

コメントを投稿