Created
October 26, 2012 19:42
-
-
Save velikodniy/3961000 to your computer and use it in GitHub Desktop.
Угадайка
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
#!/usr/bin/env python | |
# coding: utf-8 | |
data = {'question': 'Это животное?', True: 'кошка', False: 'компьютер'} | |
def ask(q): | |
a = raw_input(q) | |
if a in 'y': | |
return True | |
else: | |
return False | |
current = data | |
while True: | |
last = current | |
a = ask(current['question']) | |
current = current[a] | |
if not isinstance(current, dict): | |
if ask('Это ' + current + '?'): | |
print 'Я угадал!' | |
current = data | |
else: | |
t = raw_input('Что это?') | |
q = raw_input('Чем отличается от ' + current + '?') | |
last[a] = {'question': q, True: t, False: current} | |
current = data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment