2012年12月26日水曜日

開発環境

『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-84312-225-5) の3章(演算子と文)練習問第3-2を解いてみる。

その他参考書籍

3-2.

コード(BBEdit)

var result = "";
var a = $('#t0').val();
switch(a){
  case "one":
  case "two": result += "OK"; break;
  case "three": result += "OK1";break;
  default: result += "NONE";
}
$('#pre0').text(result);





ちなみにPython3kの場合。

コード(BBEdit)

sample.py

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

import re

while True:
    a = input()
    if re.search(r"^\s*$", a): break
    if a == "one" or a == "two":
        print("OK")
    elif a == "three":
        print("OK1")
    else:
        print("NONE")

入出力結果(Terminal)

$ ./sample.py
one
OK
two
OK
three
OK1
four
NONE

$

0 コメント:

コメントを投稿