Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
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)、Ready Bake Code(p.31)を解いてみる。
Ready Bake Code(p.31)
コード(BBEdit)
sample31.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- import random secret = random.randint(1, 10) print('Welcome!') guess = 0 while guess != secret: g = input('Guee the number(between 1 and 10): ') guess = int(g) if guess == secret: print('You win!') else: if guess > secret: print('Too high') else: print('Too low') print('Game over!')
入出力結果(Terminal)
$ ./sample31.py Welcome! Guee the number(between 1 and 10): 5 Too low Guee the number(between 1 and 10): 8 Too high Guee the number(between 1 and 10): 6 Too low Guee the number(between 1 and 10): 7 You win! Game over! $
0 コメント:
コメントを投稿