示例#1
0
def main():
    mytree = BinarySearchTree()
    i = 0
    c = '_'
    while (c != '~'):
        print(
            "Добро пожаловать. -1 - заполнить автоматом, 0 - добавить, "\
            "1 - число вершин на n-ом уровне,  2 - высота дерева, ~ - выход.")
        c = raw_input("Введите: ")
        if c == '-1':
            mytree.put(5)
            mytree.put(3)
            mytree.put(7)
            mytree.put(2)
            mytree.put(4)
            mytree.put(6)
            mytree.put(8)
            mytree.put(9)
            mytree.put(10)
        if (c == '0'):
            i = int(raw_input("Введите значение: "))
            mytree.put(i)
        elif (c == '1'):
            mytree.level = mytree.height()
            i = int(raw_input("Введите уровень: "))
            mytree.peaks = mytree.sizeTree(i, mytree.root)
            if mytree.peaks == -1:
                print("Некорректное значение(высота дерева меньше)")
            else:
                print("Число вершин: ", mytree.peaks)
        elif (c == '2'):
            mytree.level = mytree.height()
            print(mytree.level)
        elif (c == '~'):
            print("You say goodbye and I say hello!")
示例#2
0
def SynchronizationMessage(tcp):
    message = raw_input("Digite uma frase: ")

    while message != 'exit':
        channel = raw_input("Digite um canal para comunicação: ")
        message = (message + "-").encode()
        tcp.send(message)
        channel = channel.encode()
        tcp.send(channel)
        message = raw_input("Digite uma frase: ")
    tcp.close()
示例#3
0
 def length_check(submarine_size, submarine_start, submarine_end):
     # checking length
     while True:
         try:
             assert ((submarine_end - submarine_start) == submarine_size)
             return submarine_start, submarine_end
         except:
             print(Bcolors.FAIL + "wrong size" + Bcolors.ENDC)
             submarine_start = raw_input(
                 " try anther parameter set new start point")
             submarine_start = Bord.check_input(submarine_start)
             submarine_end = raw_input(
                 " try anther parameter set new end point")
             submarine_end = Bord.check_input(submarine_end)
             return submarine_start, submarine_end
             continue
         else:
             break
示例#4
0
 def check_input(input_index, filling_bord=False, hitting_competitor=False):
     """checking if the input is relevant to the game"""
     while True:
         try:
             in_index = int(input_index)
             assert (int(in_index) > 0 and (int(in_index) <= 10)
                     ), "Incorrect input, not an int between 0-10 "
             return in_index
         except Exception as e:
             print(Bcolors.FAIL + str(e.args) + Bcolors.ENDC)
             new_input = raw_input('try new input')
             return int(new_input)
             continue
         else:
             break
示例#5
0
 def orientation_validation(submarine_orientation):
     submarine_orientation = submarine_orientation.upper()
     while True:
         try:
             assert submarine_orientation == 'V' or submarine_orientation == 'H'
             return submarine_orientation
         except:
             print("not valid input")
             submarine_orientation = raw_input(
                 Bcolors.OKBLUE +
                 'choose "V" to vertical submarine or "H" to horizontal submarine'
                 + Bcolors.ENDC)
             submarine_orientation = submarine_orientation.upper()
             return submarine_orientation
             continue
         else:
             break
示例#6
0
def ask_player(mark):
    """
    Asks player where to place X or O marks, checks validity
    :param mark:
    """
    global board
    req = 'Choose where to place your: ' + mark
    while True:
        try:
            choice = int(raw_input(req))
        except ValueError:
            print("Sorry, please input a number between 1-9.")
            continue
        if board[choice] == " ":
            board[choice] = mark
            break
        else:
            print("That space isn't empty!")
            continue
示例#7
0
def play_game():
    """
    Sets marks, show board, player X/O turn
    """
    reset_board()
    global announce
    x = 'X'
    o = 'O'
    while True:
        clear_output()
        display_board()
        game_states, announce = player_choice(x)
        print(announce)
        if not game_states:
            break
        game_states, announce = player_choice(o)
        print(announce)
        if not game_states:
            break
    rematch = raw_input('Would you like to play again? y/n: ')
    if rematch == 'y':
        play_game()
    else:
        print("Thanks for playing!")
示例#8
0
from notebook.notebookapp import raw_input

name = raw_input("Input your name")
    if (args.gtts):
        try:
            from gtts import gTTS
            from pygame import mixer
            voice = "gTTS"
        except ImportError:
            import pyttsx
            print("\nInstall gTTS and pygame to use this feature." +
                  "\nUsing pyttsx\n")
    else:
        import pyttsx3

    kernel = Kernel()

    if os.path.isfile("bot_brain.brn"):
        kernel.bootstrap(brainFile="bot_brain.brn")
    else:
        kernel.bootstrap(learnFiles="std-startup.xml", commands="load aiml b")
        # kernel.saveBrain("bot_brain.brn")

    # kernel now ready for use
    while True:
        if mode == "voice":
            response = listen()
        else:
            response = raw_input("Talk to J.A.R.V.I.S : ")
        if response.lower().replace(" ", "") in terminate:
            break
        jarvis_speech = kernel.respond(response)
        print("J.A.R.V.I.S: ") + jarvis_speech
        speak(jarvis_speech)
示例#10
0
key = ''
string = ""
i = 0

# проверяем работу алгоритма
l = queue1.Queue1()
# menu = {'0': inputvar(string),
#         '1':l.add(key),
#         '2':l.Del(i),
#         '3': l.InsertNth(i, key),
#         '4': l.__str__(),
#         '~': print("You say goodbye and I say hello!")}

while(c != '~'):
    print("Добро пожаловать. 0 - заполнить очередь, 1 - добавить, 2 - удалить,  3 - вывод на экран. 4 - длинна, ~ - выход.")
    c = raw_input("Введите: ")
    if(c == '0'):
        string = raw_input("Введите значение: ")
        for i in range(len(string)):
            l.add(string[i])
    elif(c =='1'):
        key = input("Введите key: ")
        l.add(key)
    elif(c =='2'):
        i = int(input("Введите i: "))
        l.Del(i)
    # elif(c =='3'):
    #     i = int(input("Введите i: "))
    #     key = input("Введите key: ")
    #     l.InsertNth(i, key)
    elif(c =='3'):
示例#11
0
#---------------------------------

import urllib.request,sys,os,re,urllib.error
from notebook.notebookapp import raw_input
import string

def attack(phone):
    datas=""

    url='http://topic.hongxiu.com/wap/action.aspx'
    #请求的数据
    payload={'hidtpye':'1',
        'txtMobile':phone}
    #注意Referer不能为空
    i_headers = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1) Gecko/20090624 Firefox/3.5",
                  "Accept": "text/plain",'Referer':'http://topic.hongxiu.com/wap/'}
    payload=urllib.parse.urlencode(payload)

    try:
        request=urllib.Request(url,payload,i_headers)
        response=urllib.urlopen(request)
        datas=response.read()
        print (datas)
        print ('attack success!!!')
    except Exception as e:
        print(e)
        print( "attack failed!!!")

if __name__=="__main__":
    phone=raw_input('input the phone:')
    attack(phone)
示例#12
0
temp3 = []


def checkio(data):
    for itme in data:
        if itme >= 'a' and itme <= 'z':
            temp.append(itme)
        elif itme >= 'A' and itme <= 'Z':
            temp2.append(itme)
        elif itme >= '0' and itme <= '9':
            temp3.append(itme)
    if len(temp) != 0 and len(temp2) != 0 and len(temp3) != 0 and len(
            data) >= 10:
        a = True
    else:
        a = False
    # r=re.compile(r'^([0-9]+?)([A-Z]+?)([a-z]+?)$')
    #
    # r.match(data).groups()
    # if len() == 3 and len(data) >= 10:
    #     a = True
    # else:
    #     a = False
    #
    #     # replace this for solution
    # return a


data = raw_input()
print(checkio(data))
示例#13
0
from notebook.notebookapp import raw_input
from myBord import MyBord
from competitorBord import CompetitorBord

if __name__ == '__main__':

    my_bord = MyBord()

    competitor = raw_input(
        'define your competitor: press 1 to computer and 2 to anther player')

    competitor_bord = CompetitorBord()
示例#14
0
        def fill_submarine(self):

            self.filling_successful = True

            # 1. orientation
            submarine_orientation = raw_input(
                Bcolors.OKBLUE +
                'choose "V" to vertical submarine or "H" to horizontal submarine'
                + Bcolors.ENDC)
            submarine_orientation = Bord.orientation_validation(
                submarine_orientation)

            # 2. define stat point and end point
            # a. row start:
            submarine_row_start = raw_input(
                Bcolors.OKGREEN +
                'choose row for the {} size submarine starting point - the small number in the index'
                .format(self.submarine_name) + Bcolors.ENDC)
            submarine_row_start = Bord.check_input(submarine_row_start)

            # b. row end
            if (submarine_orientation == 'V'):
                submarine_row_end = raw_input(
                    Bcolors.OKGREEN +
                    'choose row for the {} size submarine end point - the big number in the index'
                    .format(self.submarine_name) + Bcolors.ENDC)
                submarine_row_end = Bord.check_input(submarine_row_end)
                submarine_row_start, submarine_row_end = Bord.length_check(
                    self.submarine_length, submarine_row_start,
                    submarine_row_end)

            # c. column start
            submarine_column_start = raw_input(
                'choose column for the {} size submarine start point - the small number in the index'
                .format(self.submarine_name))
            submarine_column_start = Bord.check_input(submarine_column_start)

            # d. column end
            if (submarine_orientation == 'H'):
                submarine_column_end = raw_input(
                    'choose column for the {} size submarine end point - the big number in the index'
                    .format(self.submarine_name))
                submarine_column_end = Bord.check_input(submarine_column_end)
                submarine_column_start, submarine_column_end = Bord.length_check(
                    self.submarine_length, submarine_column_start,
                    submarine_column_end)

            # filling lines:

            first_itaration = True
            if submarine_orientation == 'H':
                # checking
                for i in range(submarine_column_start, submarine_column_end):
                    self.collision_or_snap_check(submarine_row_start, i,
                                                 submarine_orientation,
                                                 first_itaration)
                # filling
                if self.filling_successful == True:
                    for i in range(submarine_column_start,
                                   submarine_column_end):
                        MyBord.my_cells[submarine_row_start, i] = 1
                        first_itaration = False
                else:
                    self.fill_submarine()

            if submarine_orientation == 'V':
                # checking
                for i in range(submarine_row_start, submarine_row_end):
                    self.collision_or_snap_check(i, submarine_column_start,
                                                 submarine_orientation,
                                                 first_itaration)
                # filling
                if self.filling_successful == True:
                    for i in range(submarine_row_start, submarine_row_end):
                        MyBord.my_cells[i, submarine_column_start] = 1
                        first_itaration = False
                else:
                    self.fill_submarine()
示例#15
0
def enter_str():
    str = raw_input('Введите строку: ')
    #str = list(str)
    return str
示例#16
0
import DoubleLinkedList
from notebook.notebookapp import raw_input

print("Добро пожаловать в консоль. Что будем делать?!(0 - заполнить массив, 1..3 - сортировка и вывод на экран)")
ifs = raw_input("")
示例#17
0
 def fill_deque(self, deque):
     string = raw_input("Введите строку: ")
     for i in range(0, len(string)):
         self.add(string[i])
         deque.add(string[i])
示例#18
0
import DoubleLinkedList
from notebook.notebookapp import raw_input

d1 = DoubleLinkedList.DoubleLinkedList()
d2 = DoubleLinkedList.DoubleLinkedList()
ifs = ''
'''a = {"0": d.fill_deque(),
         "1": d.sort1(),
         "2": d.sort2(),
         "3": d.sort3()
    }
'''
while ifs is not '~':
    #"Welcome. 0 - add deque, 1-3 sort seque, ~ exit")
    print(
    "\nДобро пожаловать в консоль. Что будем делать?!(0 - заполнить массив, 1..3 - сортировка и вывод на экран)")
    ifs = raw_input()
    if ifs is '0':
        d1.fill_deque(d2)
    elif ifs is '1':
        d1.sort1(d2)
    elif ifs is '2':
        d1.sort2(d2)
    elif ifs is '3':
        d1.sort3(d2)
    elif ifs is '~':
        print("FBI OPEN DOOR!")
    else:
        print("Неверно введена цифра(~ - выход)")
    # a[ifs]
示例#19
0
    def geuss_submarine(self):
        i_index = raw_input('enter row  num for guessing  submarine position - int between 0-9')
        i_index =self.check_input(i_index)

        j_index = raw_input('enter column num for guessing  submarine position - int between 0-9')
        j_index = self.check_input(j_index)