Skip to content

Instantly share code, notes, and snippets.

@velikodniy
Created October 26, 2012 19:42
Show Gist options
  • Save velikodniy/3961000 to your computer and use it in GitHub Desktop.
Save velikodniy/3961000 to your computer and use it in GitHub Desktop.
Угадайка
#!/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