Created
December 15, 2011 12:49
-
-
Save dketov/1480989 to your computer and use it in GitHub Desktop.
Угадай жЫвотное!
This file contains hidden or 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/python | |
# -*- coding: utf-8 -*- | |
class Node: | |
def __init__(self,data=None,yes=None,no=None): | |
self.data = data | |
self.yes = yes | |
self.no = no | |
def __str__(self): | |
return str(self.data) | |
root = Node() | |
def AddNewAnimal(node): | |
animal = raw_input("Введите задуманное животное: ") | |
question = raw_input("Введите вопрос, положительный ответ на который характерен для задуманного животного: ") | |
node.data = question | |
node.yes = Node(animal) | |
def CheckAnimal(node): | |
if node.yes == None and node.no == None: | |
user_input = raw_input("Это {0}? (Да/Нет) ".format(node)) | |
if user_input == "Да" or user_input == "да" : | |
return | |
else: | |
node.no = Node(node.data) | |
AddNewAnimal(node) | |
return | |
if node.yes != None : | |
user_input = raw_input("{0} (Да/Нет) ".format(node)) | |
if user_input == "Да" or user_input == "да": | |
CheckAnimal(node.yes) | |
else: | |
if node.no == None: | |
node.no = Node() | |
AddNewAnimal(node.no) | |
else: | |
CheckAnimal(node.no) | |
AddNewAnimal(root) | |
while 1: | |
CheckAnimal(root) | |
if raw_input("Продолжить игру (Да/Нет)?") == "Нет": break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment