開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
たのしいプログラミング Pythonではじめよう!(Jason R. Briggs (著)、磯蘭水・藤永奈保子・鈴木悠 (翻訳)、オーム社)の第1部(プログラムの作り方)、第9章(Python の組み込み関数)、9.4(自分でやってみよう)を取り組んでみる。
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 1. 不思議な計算結果
print((abs(10) + abs(-10)) == 20)
print((abs(-10) + -10) == 0)
# 2. 秘密のメッセージ
s = (
'this if is you not are a reading very this good then way you to have '
'hide done a it message wrong'
)
str_list = s.split()
import pprint
pprint.pprint(str_list)
for i, word in enumerate(str_list):
if i % 2 == 0:
print(word, end=' ')
print()
# 3. ファイルのコピー
with open('sample1.py') as in_f, open('sample2.py', 'w') as out_f:
for line in in_f:
print(line, end='', file=out_f)
入出力結果(Terminal, IPython)
$ ./sample1.py True True ['this', 'if', 'is', 'you', 'not', 'are', 'a', 'reading', 'very', 'this', 'good', 'then', 'way', 'you', 'to', 'have', 'hide', 'done', 'a', 'it', 'message', 'wrong'] this is not a very good way to hide a message $ diff sample1.py sample2.py $
0 コメント:
コメントを投稿