Esempio n. 1
0
def b_call(event):
    """
    Button functionality stuff
    """
    a = Choice('investing', slope_input.value, int_input.value)
    b = Choice('not investing', var_input.value)

    ALL = slice(len(df.data['x']))

    df.patch({
        'y': [(ALL, df.data['x'] * a.slope + a.inter)],
        'y2': [(ALL, df.data['x'] * b.slope)]
    })

    try:
        diff = Choice.when_equal(a, b)
        BUF = 10
        SOL = diff['sol']['x']
        eq_solve.location = SOL
        answer.text = diff['descr']

        p.x_range.start = SOL - BUF
        p.x_range.end = SOL + BUF

        p.y_range.start = diff['sol']['y'] - BUF
        p.y_range.end = diff['sol']['y'] + BUF

    except ValueError:
        eq_solve.location = 0
        answer.text = 'There isnt a solution'
Esempio n. 2
0
 def __init__(self):
     # 初始化程序
     self.download = Downloader()
     self.parser = HtmlParser()
     self.save = SaveData()
     self.workbook = Workbook()
     self.ch = Choice()
     print('初始化完成...')
 def __init__(self):
     """
     Initialize a new UI with a background image and
     """
     self.root = None
     self.init_window()
     self.new_choice = Choice()
     self.set_background()      # To set the background image in place
     self.count = 0
Esempio n. 4
0
 def _purchase_or_play_treasure_choice(self, player):
     return Choice(
         player.get_name(),
         list({(ChoiceType.play, card.name)
               for card in player.get_hand()
               if card.type == CardType.treasure}) +
         [(ChoiceType.buy, card.name)
          for card in self._cards_available_at(player.get_available_spend())
          ] + [(ChoiceType.end_turn, )])
Esempio n. 5
0
class SpiderMain(object):
    def __init__(self):
        # 初始化程序
        self.download = Downloader()
        self.parser = HtmlParser()
        self.save = SaveData()
        self.workbook = Workbook()
        self.ch = Choice()
        print('初始化完成...')

    def run(self):
        while True:
            try:
                p = int(input('想要爬多少页的数据?' + '\n'))
                break
            except ValueError:
                print('输入错误!请输入数字')
        page = p + 1
        print("================================")
        print(' A.原创发布区     B.精品软件区    ')
        print(' C.脱壳破解区     D.移动安全区    ')
        print(' E.病毒分析区     F.编程语言区    ')
        print(' G.软件调试区     H.动画发布区    ')
        print(' I.逆向资源区     J.安全工具区    ')
        print(' K.招聘求职区                    ')
        print("================================")
        while True:
            choice = input("选择爬取的专区,输入 Q 退出程序(输入的字母必须大写):")
            half_url, name = self.ch.make_the_arrg(choice)
            if name != 'Error':
                break
        print(half_url + '\n' + name)
        self.save.createfile(name)
        for i in range(1, page):
            url = half_url + str(i) + '.html'
            response = self.download.download(url)
            self.parser.parser(response, name)
            sleep = random.randint(2, 10)
            print('爬取第' + str(i) + '页完成,程序休息' + str(sleep) + '秒')
            time.sleep(sleep)  # 程序睡眠
            if i != page - 1:
                print('-----------------------------')
                print('          下一页              ')
                print('-----------------------------')
        print('数据写入完成,正在进行数据去重...')
        self.save.delete_same_data()
        try:
            self.workbook.save('将csv的数据导入此表.xlsx')
        except:
            print('创建xlsx文件失败,请手动创建')
        print('程序运行完毕')
Esempio n. 6
0
from choice import Choice
from schoolFileReader import SchoolFileReader

while True:
    print("이용하고 싶은 서비스를 입력해주세요 : ")
    print("1. 관심있는 분야의 고등학교 알아보기\n2. 마이페이지")

    write = input()

    if write == "1":
        c = Choice()
        c.choice()

        while True:
            print("다시 시작하시겠습니까 ?(y / n) ")
            answer = input()

            if answer == "y":
                print(
                    "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n다시 시작합니다 ! "
                )
                break
            elif answer == "n":
                print("종료합니다 ! ")
                break
            else:
                print("다시 입력 해주세요")

    elif write == "2":
        fr = SchoolFileReader()
        fr.schoolFileReader()
Esempio n. 7
0
    conf = Configuration(storage, config)
    questions = load_database(config.get("db", "questions"))
    msgdb = MessageDatabase(questions)
    pingpong = PingPong()
    alphabet = Alphabet(storage, conf)
    count = Count(storage, conf)
    greet = Greet(
        [x.strip() for x in config.get("modules", "greetings").split(",")],
        nick)
    flooding = Flooding(conf)

    search_engines = load_database(config.get("db", "searchengines"))
    search = Search(search_engines)
    #expression = Expression()
    actions = Actions(storage)
    choice = Choice(conf)
    scripting = Scripting(storage, search_engines=search_engines)
    fatfox = FatFox()
    burgi = Burgi()
    cookies = Cookies()
    #urltitle = Urltitle()
    #finder = Finder()
    hands = Hands(storage, conf, config.get("modules", "hands"))
    weather = Weather(storage, conf, config.get("modules", "hands"))
    mute = Mute(storage)

    conf.add_handler('mute', mute.config_handler)
    conf.add_handler(['show', 'mute'], mute.show_handler)
    conf.add_handler(['show', 'participants'], status.show_participants)
    conf.add_handler(['show', 'online', 'users'], status.show_online_users)
Esempio n. 8
0
 def add_choice(self, description, res_moment):
     self.choices_.append(Choice(description, res_moment))
Esempio n. 9
0
    "MenuFrauenhoferParser": MenuFrauenhoferParser,
    "MenuSolarParser": MenuSolarParser,
    "FoodTruckParser": FoodTruckParser,
    "NullParser": NullParser
}

choices = []
for ident, args in config.items("restaurants"):
    logging.info("Loading parser: %s (%s)" % (ident, args))
    argList = [item.strip() for item in args.split(",")]
    parserClass = PARSER[argList[1]]
    if parserClass is None:
        logging.error("No parser class found: %s" % argList[1])
        continue
    parser = parserClass(argList[2])
    choice = Choice(ident, argList[0], parser)
    choices.append(choice)

GuessingGabin.databasePath = os.path.join(BASE_DIR,
                                          config.get("misc", "dbpath"))

log = logging.getLogger('werkzeug')
log.setLevel(logging.WARNING)

voteFormGenerator = VoteFormGenerator(VERSION, choices)


@app.route('/', methods=['GET', 'POST'])
def showVoteForm():
    return voteFormGenerator.getVoteForm()
Esempio n. 10
0
 def __init__(self, name, names, maxPlayers):
     self._name = name
     self._choices = list(map(lambda n: Choice(n), names))
     self._maxPlayers = maxPlayers
Esempio n. 11
0
def comment(text):
    return "\n".join(["# %s" % line for line in text.splitlines()])


#=============================================================================
# Create the Plan object: we need to add all the possible choices a user may
# want to make and the code to use for each choice.
plan = ChoiceList("I'm now going to ask a few questions in order to build a "
                  "plan for making the distribution (a plan is just a shell "
                  "script that you can run to re-create the distribution so "
                  "that you don't need to answer the same questions again "
                  "and again).")

use_def_un = plan.add_choice(
    Choice("Which username should I use to access "
           "the repositories?"))
use_def_un.add_alternative(Alternative("Use '%s'." % username))
use_def_un.add_alternative(Alternative("Use a different username."))

what_un = plan.add_choice(OpenQuestion("What username shoud I use?"))
what_un.when_should_ask(lambda: use_def_un.chosen == 1)

want_ctr = plan.add_choice(
    Choice("Which repositories do you want to use as "
           "source for building the tarball?"))
want_ctr.add_alternative(Alternative("Use the central repositories."))
want_ctr.add_alternative(
    Alternative("Use the current repository for src and "
                "central repositories for doc and test."))

want_old = plan.add_choice(
Esempio n. 12
0
 def addChoice(self, name):
     if not self.hasChoice(name):
         self._choices.append(Choice(name))
Esempio n. 13
0
 def add_choice(self, description, res_moment):
     self.choices_ = [Choice(description, res_moment)] + self.choices_
class Ui:
    """
    Create a new UI for the game
    """

    def __init__(self):
        """
        Initialize a new UI with a background image and
        """
        self.root = None
        self.init_window()
        self.new_choice = Choice()
        self.set_background()      # To set the background image in place
        self.count = 0

    def init_window(self):
        """
        This function enables creating of new windows everytime we click a button
        :return: None
        """
        if self.root:  # If there is a root
            self.root.destroy()  # Destroy the root
        self.root = Tk()  # Makes a new root
        self.root.geometry("1800x1800")
        self.root.title("Rock,Paper,Scissors, Spock,Lizard")
        self.player_frame = Frame(self.root, padx=100, pady=200, background="orange")
        self.player_frame.place(x=300, y=100)
        self.computer_frame = Frame(self.root, padx=100, pady=200, background="light blue")
        self.computer_frame.place(x=800, y=100)
        self.entered_name = False

        self.compScoreLabelText = StringVar()  # Makes a Tkinter string variable
        self.playerScoreLabelText = StringVar()  # Makes a Tkinter string variable
        self.compChoiceLabelText = StringVar()  # Makes a Tkinter string variable
        self.playerChoiceLabelText = StringVar()  # Makes a Tkinter string variable
        self.displayed_player_score = StringVar()
        self.displayed_computer_score = StringVar()
        self.winnerName = StringVar()  # Makes a Tkinter string variable
        self.another_choice_button = Button(self.root, text="Make another choice", height=5, width=18,
                                            background="light green", command=self.play_again)
        self.quit_match = Button(self.root, text="QUIT MATCH", height=5, width=15, background="tomato",
                                 command=self.quit_game)
        self.quit_match.place(x=675, y=600)
    def set_background(self):
        """
        This function creates a canvas for the background image
        :return: None
        """
        self.project_image_canvas = Canvas(self.root, height=1500, width=1800)
        self.background = PhotoImage(file="image/background.png")
        self.project_image_canvas.create_image(700, 450, image=self.background)
        self.project_image_canvas.pack()

    def start_game(self):
        """
        This function enables the start of the game by displaying the title,
        then calls the make choice  and display_updated_choice functions
        :return: None
        """


        self.init_window()
        self.make_choice()
        self.display_updated_choice()

        self.another_choice_button.place(x=670, y=300)

    def user_guide(self):
        """
        This functions gives instructions to the user on how to play the game
        :return: None
        """
        self.init_window()
        self.general_instruction = Label(self.root, text="""***HOW TO PLAY***\n
        1.When you hit the start Game Button, your web cam is launched\n 
        2.Ensure to position fingers according a symbol(shown below) that represents your choice \n
        3. Then click "s" on your keyboard to save the choice made!
          The rock,paper, scissors,lizard, and spock representations are as shown below\n
        **The winner of the match is announced after five choices are made**""", pady=50)
        self.general_instruction.config(font=("Helvetica", 18))
        self.general_instruction.pack()
        self.background_canvas = Canvas(self.root, height=1800, width=1800, background=None)
        self.rock_image = PhotoImage(file="image/rock.png")
        self.background_canvas.create_image(290, 90, image=self.rock_image)
        self.paper_image = PhotoImage(file="image/paper.png")
        self.background_canvas.create_image(520, 90, image=self.paper_image)
        self.scissors_image = PhotoImage(file="image/scissors.png", )
        self.background_canvas.create_image(750, 90, image=self.scissors_image)
        self.lizard_image = PhotoImage(file="image/lizard.png")
        self.background_canvas.create_image(1135, 90, image=self.lizard_image)
        self.spock_image = PhotoImage(file="image/spock.png")
        self.background_canvas.create_image(975, 90, image=self.spock_image)

        self.back_button = Button(self.background_canvas, text="BACK", height=5, width=15, background="tomato",command=self.back_button_handler)
        self.background_canvas.create_window(750, 260, window=self.back_button)
        # self.back_button.place(x=1200, y=300)
        self.background_canvas.pack()

    def back_button_handler(self):
        """
        This is the button handler for the back button after reading the instructions on how to play the game
        :return: None
        """
        self.init_window()
        self.set_background()
        self.create_welcome_window()

    def make_choice(self):
        """
        This function manages the players choice
        Creates a player board
        Calls the identify_player_choice function to identify what choice the user makes
        It displays the player's choice and score
        :return: None
        """
        # To take in and identify the player's choice from the webcam'
        self.new_choice.identify_player_choice()
        # Make a computer choice
        self.new_choice.take_computer_choice()
        # Compare these choices
        self.new_choice.compare_choices()
        # Set the choices to variables
        self.displayed_player_score = self.new_choice.player_score
        self.displayed_computer_choice = self.new_choice.computer_choice

    def display_updated_choice(self):
        """
        This function managaes the computer score board
        It enables the computer to make a random choice
        It displays the choice and score of the computer
        :return:None
        """
        self.count += 1
        print("count{0}".format(self.count))
        # Set the player label, with font
        self.player_choiceBoard = Label(self.player_frame, text="PLAYER")
        self.player_choiceBoard.config(font=("Helvetica", 18))
        self.player_choiceBoard.pack()
        # Add a separator with height 2
        self.player_space_up = Label(self.player_frame, text="", background="orange", height=2)
        self.player_space_up.pack()
        # Make a player choice label
        self.displayed_player_choice = self.new_choice.player_choice
        self.player_choiceBoard = Label(self.player_frame, text="Choice: ")
        self.player_choiceBoard.pack(side=LEFT)
        # Show the displayed choice
        self.playerChoiceLabelText.set(self.displayed_player_choice)
        self.player_choice_Label = Label(self.player_frame, textvariable=self.playerChoiceLabelText)
        self.player_choice_Label.pack(side=LEFT)
        # Separate the choice label and the choice value
        self.player_space = Label(self.player_frame, text="", background="orange", width=5)
        self.player_space.pack(side=LEFT)

        # Player score gets updated
        self.player_scoreBoard = Label(self.player_frame, text="Score: ")
        self.player_scoreBoard.pack(side=LEFT)
        self.displayed_player_score = self.new_choice.player_score
        self.playerScoreLabelText.set(self.displayed_player_score)
        self.player_score_Label = Label(self.player_frame, textvariable=self.playerScoreLabelText)
        self.player_score_Label.pack(side=LEFT)  # pack means add to window
        # make a computer choice label
        self.computer_choiceBoard = Label(self.computer_frame, text="COMPUTER")
        self.computer_choiceBoard.config(font=("Helvetica", 18))
        self.computer_choiceBoard.pack()
        # To add a separator with height of 2
        self.computer_space_up = Label(self.computer_frame, text="", background="light blue", height=2)
        self.computer_space_up.pack()
        self.comp_choiceBoard = Label(self.computer_frame, text="Choice:")
        # Make a choice board for the computer choice
        self.displayed_computer_choice = self.new_choice.computer_choice
        self.comp_choiceBoard.pack(side=LEFT)
        self.compChoiceLabelText.set(self.displayed_computer_choice)
        # Add the choice label for the computer choice
        self.comp_choice_Label = Label(self.computer_frame, textvariable=self.compChoiceLabelText)
        self.comp_choice_Label.pack(side=LEFT)  # pack means add to window
        # To add a separator between choice and score
        self.comp_space = Label(self.computer_frame, text="", background="light blue", width=5)
        self.comp_space.pack(side=LEFT)
        # The computer score board display
        self.comp_scoreBoard = Label(self.computer_frame, text="Score: ")
        self.comp_scoreBoard.pack(side=LEFT)
        self.displayed_computer_score = self.new_choice.computer_score
        self.compScoreLabelText.set(self.displayed_computer_score)
        self.comp_score_Label = Label(self.computer_frame, textvariable=self.compScoreLabelText)
        self.comp_score_Label.pack()
        self.comp_score_Label.pack(side=LEFT)

        # If the player and computer have made three choices, then declare a winner and restart another match
        if self.count == 5:
            self.display_winner()
            self.new_choice.player_score = 0
            self.new_choice.computer_score = 0

    def play_again(self):
        """
        This function is to enable continuous playing
        It is called when the user clicks the make another choice button
        :return: None
        """
        self.init_window()
        self.make_choice()
        self.display_updated_choice()
        self.another_choice_button.place(x=670, y=300)
        self.quit_Button.pack()
    def restart_game(self):
        """
        This function enables the player to restart the game after displaying the winner
        It enables another round of five choices to be made
        :return: None
        """
        self.init_window()
        self.make_choice()
        self.display_updated_choice()
        self.another_choice_button.place(x=670, y=300)
    def set_winner_screen(self):
        """
        This function creates the screen on which the winner of the game is displayed
        :return: None
        """
        self.project_image_canvas = Canvas(self.root, height=1500, width=1800)
        self.background = PhotoImage(file="background.png")
        self.project_image_canvas.create_image(700, 450, image=self.background)
        self.project_image_canvas.pack()
    def display_winner(self):
        """
        This function prints who has won the game
        :return:Nones
        """
        self.set_background()
        self.count=0
        self.play_again_button=Button(self.root,text="PLAY AGAIN",height=5, width=15, background="light green",command=self.restart_game)
        self.play_again_button.place(x=200,y=50)
        # If the computer score is higher than the player score
        if self.displayed_computer_score > self.displayed_player_score:
            comp_win_label = Label(self.root, text="Computer wins", foreground="blue")
            comp_win_label.config(font=("Helvetica", 50))
            comp_win_label.place(x=550, y=40)
        # If the player score is higher than the computer score
        elif self.displayed_computer_score < self.displayed_player_score:
            player_win_label = Label(self.root, text="Player wins", foreground="orange")
            player_win_label.config(font=("Helvetica", 50))
            player_win_label.place(x=550, y=40)
        # If both scores are equal
        elif self.displayed_computer_score == self.displayed_player_score:
            draw_label = Label(self.root, text="Equal scores. This is a draw", foreground="red")
            draw_label.config(font=("Helvetica", 50))
            draw_label.place(x=400, y=40)


    def quit_game(self):
        """
        This function is a handler for the quit game button
        :return: None
        """
        self.root.destroy()

    def create_welcome_window(self):
        """
        This function creates the UI for the welcome screen
        :return: None
        """
        # The game title
        self.game_title = Label(self.root, text="ROCK,PAPER,SCISSORS,LIZARD, SPOCK", foreground="blue")
        self.game_title.config(font=("Courier", 40))
        # The mini instructions on how to navigate the welcome
        self.instruction = Label(self.root,
                                 text="Click Start to take your first choice, or Quit to exit the game.\n Click How to play for instructions on how to play the game")
        self.instruction.config(font=("Courier", 15))
        self.game_title.place(x=100, y=100)
        self.instruction.place(x=250, y=200)
        self.quit_match.destroy()
        # Craete the buttons on the welcome screen
        self.play_Button = Button(self.root, text="START GAME", height=5, width=15, background="light green",
                                  command=self.start_game, )
        self.quit_Button = Button(self.root, text="QUIT GAME", height=5, width=15, background="tomato",
                                  command=self.quit_game)
        self.user_guide_Button = Button(self.root, text="HOW TO PLAY", height=5, width=15, background="yellow",
                                        command=self.user_guide)
        self.play_Button.place(x=400, y=400)
        self.quit_Button.place(x=900, y=400)
        self.user_guide_Button.place(x=650, y=500)
        self.root.mainloop()
Esempio n. 15
0
 def add_choice(self, description, res_node):
     self.choices_ = [Choice(description, res_node)] + self.choices_
     print("INFO: New choice added: links node " + self.name_ + " with node " + res_node.name_ + ".")
Esempio n. 16
0
question_list = []

for line in questions_and_answers:
    question_data = line.strip().split(';')

    question = question_data[0]

    a = question_data[1]
    b = question_data[2]
    c = question_data[3]
    d = question_data[4]

    answer = question_data[5]

    question_list.append(Question(question, Choice(a, b, c, d), answer))

questions_and_answers.close()
print_ascii('welcome.txt')

number_of_correct = 0

for question in question_list:
    print(question.question + '\n')
    choices = question.choices
    print("(A) " + choices.a)
    print("(B) " + choices.b)
    print("(C) " + choices.c)
    print("(D) " + choices.d + "\n")

    answer = input("Your Answer: ")
Esempio n. 17
0
 def _choice_f(screen, choose_from_list, **kwargs):
     choice_handler = Choice(screen, choose_from_list, **kwargs)
     return choice_handler.get_result()