2014年4月28日月曜日

開発環境

Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter1(Starting to Code: Finding your way)、Pool Puzzle(p.23)を解いてみる。

Pool Puzzle(p.23)

コード(BBEdit)

sample23.py

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

print('Welcome!')
g = input('Guee the number: ')
guess = int(g)

if guess == 5:
    print('You win!')
else:
    if guess > 5:
        print('Too high')
    else:
        print('Too low!')

print('Game over!')

入出力結果(Terminal)

$ ./sample23.py
Welcome!
Guee the number: 4
Too low!
Game over!
$ ./sample23.py
Welcome!
Guee the number: 5
You win!
Game over!
$ ./sample23.py 
Welcome!
Guee the number: 6
Too high
Game over!
$

0 コメント:

コメントを投稿