2015年7月17日金曜日

開発環境

  • 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 8.(How to Use Classes and Objects)、Programming Puzzles #1: The Giraffe shuffle(No. 2030)を解いてみる。

Programming Puzzles #1: The Giraffe shuffle(No. 2030)

コード(Emacs, BBEdit)

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

class Giraffes:
    def leftFootForward(self):
        print('left foot forward')
    def rightFootForward(self):
        print('right foot forward')
    def dance(self):
        self.leftFootForward()
        self.leftFootForward()
        self.rightFootForward()
        self.rightFootForward()
        self.leftFootForward()
        self.rightFootForward()
        self.rightFootForward()
        self.leftFootForward()
        
reginald = Giraffes()
reginald.dance()

入出力結果(Terminal, IPython)

$ ./sample1.py
left foot forward
left foot forward
right foot forward
right foot forward
left foot forward
right foot forward
right foot forward
left foot forward
$

0 コメント:

コメントを投稿

Comments on Google+: