2015年8月7日金曜日

開発環境

  • 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 9.(Python's Built-in Functions)、Programming Puzzles #3: Copying a File(No. 2474)を解いてみる。

Programming Puzzles #3: Copying a File(No. 2474)

コード(Emacs, BBEdit)

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

with open('sample2.py') as in_fh, open('copied.txt', 'w') as out_fh:
    for line in in_fh:
        print(line, file=out_fh, end='')

入出力結果(Terminal, IPython)

$ ./sample3.py
$ cat copied.txt 
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

s = 'this if is you not are a reading very this good then way you to hide done a it message wrong'

words = s.split()

for i in range(0, len(words), 2):
    print(words[i], end=' ')
print()

for i in range(1, len(words), 2):
    print(words[i], end=' ')
print()
$ diff sample2.py copied.txt 
$ 

0 コメント:

コメントを投稿