Changeset 934ac23a0313…
Parent 83feb398eb90…
by Benjamin Pollack
Changes to one file · Browse files at 934ac23a0313 Showing diff from parent 83feb398eb90 Diff from another changeset...
@@ -1,48 +1,48 @@ - #!/usr/bin/env python
-
-from brain import load, save
-
-BRAIN_DB = 'brain.db'
-
-def ask(question):
- while True:
- print question,
- answer = raw_input().strip().lower()
- if answer in ('y', 'yes', 'yeah', 'si'):
- return True
- elif answer in ('n', 'no', 'nope'):
- return False
- else:
- print 'Please type "yes" or "no"'
-
-def play():
- questioner = load(BRAIN_DB)
- questioner.start()
- while True:
- question = questioner.next_question()
- question.ask()
- if questioner.solved():
- print 'I got it!'
- if ask('Play again? '):
- questioner.start()
- else:
- save(BRAIN_DB, questioner)
- exit()
- else:
- if questioner.out_of_ideas():
- print 'I give up. What were you thinking of?'
- thing = raw_input()
- if questioner.needs_clarification():
- print 'What is a question whose answer is "true" for %s, but "false" for %s?' % (thing, questioner.best_guess())
- question = raw_input()
- questioner.learn_thing_and_question(question, thing)
- else:
- questioner.learn_thing(thing)
- if ask('Play again?'):
- questioner.start()
- else:
- save(BRAIN_DB, questioner)
- exit()
-
-if __name__ == '__main__':
- play()
+#!/usr/bin/env python
+
+from brain import load, save
+
+BRAIN_DB = 'brain.db'
+
+def ask(question):
+ while True:
+ print question,
+ answer = raw_input().strip().lower()
+ if answer in ('y', 'yes', 'yeah', 'si'):
+ return True
+ elif answer in ('n', 'no', 'nope'):
+ return False
+ else:
+ print 'Please type "yes" or "no"'
+
+def play():
+ questioner = load(BRAIN_DB)
+ questioner.start()
+ while True:
+ question = questioner.next_question()
+ question.ask()
+ if questioner.solved():
+ print 'I got it!'
+ if ask('Play again? '):
+ questioner.start()
+ else:
+ save(BRAIN_DB, questioner)
+ exit()
+ else:
+ if questioner.out_of_ideas():
+ print 'I give up. What were you thinking of?'
+ thing = raw_input()
+ if questioner.needs_clarification():
+ print 'What is a question whose answer is "true" for %s, but "false" for %s?' % (thing, questioner.best_guess())
+ question = raw_input()
+ questioner.learn_thing_and_question(question, thing)
+ else:
+ questioner.learn_thing(thing)
+ if ask('Play again?'):
+ questioner.start()
+ else:
+ save(BRAIN_DB, questioner)
+ exit()
+
+if __name__ == '__main__':
+ play()
|
Loading...