2015年6月20日土曜日

開発環境

  • 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 5(Asking Questions with if and else)、Programming Puzzles(No. 1206)を解いてみる。

Programming Puzzles(No. 1206)

コード(Emacs, BBEdit)

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

print('#2')
def test(twinkies):
    if twinkies < 100 or 500 < twinkies:
        print('Too few or too many')

test(99)
test(100)
test(499)
test(500)
test(501)

print('#3')
def test(money):
    if 100 <= money <= 500 or 1000 <= money <= 5000:
        print('Too few or too many')
        
test(200)
test(700)
test(1200)
test(10000)

print('#4')
ninjas = 5
if ninjas < 10:
    print('I can fight those ninjas!')
elif ninjas < 30:
    print("It'll be a struggle, but I can take 'em")    
elif ninjas < 50:
    print("That's too many")

入出力結果(Terminal, IPython)

$ ./sample.py
#2
Too few or too many
Too few or too many
#3
Too few or too many
Too few or too many
#4
I can fight those ninjas!
$

0 コメント:

コメントを投稿