Created
December 29, 2013 00:17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parser: | |
u"""REPLのRead部分を司る""" | |
phase = 'introduction' | |
def __init__(self): | |
pass | |
def read(self): | |
u"""入力関数 | |
phaseの情報によって動作が変わる""" | |
if self.phase == 'input-numbers': | |
return (self.phase, self.__integer()) | |
elif self.phase == 'play-again?' or\ | |
self.phase == 'instruction': | |
return (self.phase, self.__yes_or_no_p()) | |
else: | |
return (self.phase, None) | |
def __integer(self): | |
u"""整数の入力をコントロール""" | |
var = raw_input() | |
try: return int(var) | |
except ValueError: | |
return self.__integer() | |
def __yes_or_no_p(self): | |
u"""入力がYesかNoか判定して真偽値を返す""" | |
def y_or_n_p(string): | |
if string.upper() in ('Y', 'YES'): | |
return True | |
else: | |
return False | |
t = ('Y', 'YES', 'N', 'NO') | |
i = raw_input() | |
if i.upper() in t: | |
return y_or_n_p(i) | |
else: | |
return self.__yes_or_no_p() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment