def main(): """ Method connects to Telegram API and checks the new messages in a chat And sends the diagram as respond in the case If message equals 'w' or 'wind' In the next version: - Should be added the checkong function for API's """ telegram_token = string('Please enter a token for Telegram API ') telegram_bot = TelegramApi(telegram_token) open_weather_token = string('Please enter a token for OpenWeather API ') city = string('Please enter a city ') openweather_parcer = OpenWeatherApi(city, open_weather_token) print('Successfully') new_offset = None while True: new_messages = telegram_bot.get_updates(new_offset) if new_messages == []: pass else: chat_attributes = telegram_bot.get_chat_attributes(new_messages) last_update_id, chat_id, message = chat_attributes.values() if message in ['w', 'wind']: x, y = openweather_parcer.get_x_and_y() graph = create_graph(x, y) response = telegram_bot.send_photo(chat_id, graph) print(response) else: print("""I couldn't recognize the message. Please type 'w' or 'wind'""") new_offset = last_update_id + 1 print(new_messages)
def play_game(game): """Run provided game. Args: game: a game module from ./games. Should contain function generate_round and constant OBJECTIVE """ print('Welcome to the Brain Games!') name = prompt.string('May I have your name? ') print('Hello, {0}!'.format(name)) print(game.OBJECTIVE) current_round = 0 while current_round < ROUNDS_COUNT: current_round += 1 (question, answer) = game.generate_round() print('Question: {0}'.format(question)) player_answer = prompt.string('Your answer: ') if player_answer != answer: print('{0} is wrong answer ;(. Correct answer was {1}'.format( player_answer, answer, )) print("Let's try again, {0}!".format(name)) return print('Correct!') print('Congratulations, {0}!'.format(name))
def run(game: typing.Optional = None, rounds_total: int = 3): print('Welcome to the Brain Games!') if game is not None: print(game.DESCRIPTION) name = prompt.string('May I have your name? ') print(f'Hello {name}') if game is not None: current_round_num = 0 while current_round_num < rounds_total: question, answer = game.prepare_round() print(f'Question: {question}') user_answer = prompt.string("Your answer: ") if user_answer == answer: print('Correct!') current_round_num += 1 else: print(f"'{user_answer}' is wrong answer ;(. " f"Correct answer was '{answer}'.\n" f"Let's try again, {name}!") return print(f'Congratulations! {name}')
def run(game, counter=3): """Game engine. Parameters: game(module): module with game. counter (int, optional): number of rounds """ print('Welcome to the Brain Games!') print(game.RULES) username = prompt.string('May I have your name? ') print('Hello, {name}!\n'.format(name=username)) while counter > 0: question, expected_answer = game.get_round_data() print('Question: {question}'.format(question=question)) actual_answer = prompt.string('Your answer: ') if expected_answer != actual_answer: print(( '"{actual}" is wrong answer ;(. ' 'Correct answer was "{expected}"\n' # noqa: WPS326 "Let's try again, {name}!" # noqa: WPS326 ).format( actual=actual_answer, expected=expected_answer, name=username, )) return print('Correct!\nCongratulations, {name}!'.format(name=username)) counter -= 1
def play_game(game): """Game engine. Parameters: game: game module """ print('Welcome to the Brain Games!') print('{0}\n'.format(game.GAME_DESCRIPTION)) username = string('May I have your name? ') print('Hello, {0}!\n'.format(username)) count = 0 # extract question, answer from generate_game_data while count < NUMBER_OF_QUESTIONS: (question, answer) = game.generate_game_data() print(question) user_answer = string('Your answer: ') # user input if user_answer == answer: print('Correct!') count += 1 else: print( """'{0}' is wrong answer ;(. Correct answer was '{1}'. Let's try again, {2}! """.format(user_answer, answer, username), ) return print('Congratulations, {0}!'.format(username))
def run(game): print('Welcome to the Brain Games!') print(game.TASK) player_name = prompt.string('May I have your name? ') print(f'Hello, {player_name}!') count_remaining_attempts = 3 while count_remaining_attempts != 0: question, correct_answer = game.create_game() print(f'Question: {question}') user_answer = prompt.string('Your answer: ') if user_answer != correct_answer: print(f'{user_answer} is wrong answer ;(.' f'Correct answer was {correct_answer}.') print(f'Let\'s try again, {player_name}!') break print('Correct!') count_remaining_attempts -= 1 if count_remaining_attempts == 0: print(f'Congratulations, {player_name}!')
def engine(game_brain, rule_game): """Game engine. Args: game_brain: function any game module rule_game: function """ print('Welcome to the Brain Games!') name = prompt.string('May I have your name? ') print('Hello, {0}'.format(name)) rule_game() count_correct_answer = 0 while count_correct_answer < 3: question, result = game_brain() print('Question: {0}'.format(question)) answer_user = prompt.string('Your answer: ') if answer_user == result: print('Correct!') count_correct_answer += 1 continue correct_answer = "'{0}' is wrong answer ;(. Correct answer was '{1}'." print(correct_answer.format(answer_user, result)) print("Let's try again, {0}!".format(name)) break if count_correct_answer == 3: print('Congratulations, {0}!'.format(name))
def run(games_obj): print('Welcome to the Brain Games!') print(games_obj.greeting()) nam_user = prompt.string('May I have your name? ') print("Hello, {}!".format(nam_user)) i = 1 while i <= QUESTION_NUMBER: str_to_question, correct_ans = games_obj.main_action() print('Question: {}'.format(str_to_question)) answer = prompt.string('Your answer: ') if correct_ans != answer: print("'{}' is wrong answer ;(. Correct answer was '{}'.".format( answer, correct_ans)) print("Let's try again, {}!".format(nam_user)) break print('Correct!') i += 1 else: print("Congratulations, {}!".format(nam_user))
def engine(game): """ Game engine. Parameters: game: module of the game Returns: None """ print('Welcome to the Brain Games!') name_user = prompt.string('May I have your name? ') print('Hello, {0}!'.format(name_user)) print(game.GAME_RULE) for _ in range(ROUNDS_COUNT): task, correct_answer = game.get_task_and_solution() print('Question: {0}'.format(task)) answer_user = prompt.string('Your answer: ') if answer_user == correct_answer: print('Correct!') continue show_game_over(answer_user, correct_answer, name_user) break else: print('Congratulations, {0}!'.format(name_user))
def play(game): """Plays the game. Args: game: certain game """ print('Welcome to the Brain Games!') user_name = prompt.string('May I have your name? ') print(f'Hello, {user_name}!') print(game.GAME_RULE) game_rounds_count = 3 for _ in range(0, game_rounds_count): question, correct_answer = game.get_question_and_correct_answer() print(f'Question: {question}') user_answer = prompt.string('Your answer: ') if user_answer != correct_answer: print( f"'{user_answer}' is wrong answer ;(. " + f"Correct answer was '{correct_answer}'.\n" + f"Let's try again, {user_name}!", ) return print('Correct!') print(f'Congratulations, {user_name}!')
def play(game): """ Game flow. Args: game: game to play """ print('Welcome to the Brain Games!') print('{0}\n'.format(game.DESCRIPTION)) name = prompt.string('\nMay I have your name? ') print('Hello, {user}!\n'.format(user=name)) won_rounds = 0 while won_rounds < NUMBER_OF_ROUNDS: question, correct_answer = game.get_task() print(question) user_answer = prompt.string('Your answer: ') if user_answer != correct_answer: print("'{0}' is wrong answer ;(. Correct answer was '{1}'".format( user_answer, correct_answer, )) print("Let's try again, {0}!".format(name)) return print('Correct!') won_rounds += 1 print('Congratulations, {0}!'.format(name))
def start_engine(game): print("Welcome to the Brain Games!") user_name = prompt.string('May I have your name? ') print('Hello, ' + user_name + '!') roundsCount = 3 task = game.task print(task) round = 0 while roundsCount != round: question, true_answer = game.get_round_data() print('Question: {}'.format(question)) user_answer = prompt.string("Your answer: ") if true_answer == user_answer: print('Correct!') round += 1 else: print('\'{}\' is wrong answer ;(.'.format(user_answer), end='') print(' Correct answer was \'{}\'.'.format(true_answer)) print('Let\'s try again, {}!'.format(user_name)) return print('Congratulations, {}!'.format(user_name))
def play_game(game): print() print('Welcome to the Brain Games!') print(game.DESCRIPTION) print() user_name = prompt.string('May I have your name? ') print('Hello, {}!'.format(user_name)) count = 0 # number of correct answers to finish the game while count < ROUNDS_COUNT: question, correct_answer = game.generate_question_and_answer() print('Question: {}'.format(question)) answer = prompt.string('Your answer: ') if answer == correct_answer: print('Correct!') count += 1 else: print("'{}' is wrong answer ;(. Correct answer was '{}'.".format( answer, correct_answer)) print("Let's try again, {}!".format(user_name)) print("Congratulations, {}!".format(user_name))
def run_game(brain_game): """ Create a 3-round game session for all of brain games modules. Args: brain_game: game module of choosen game. """ print('Welcome to the Brain Games!') name = prompt.string('May I have your name? ') print('Hello, {0}!'.format(name)) print(brain_game.GAME_RULES) for _ in range(GAME_ROUNDS): question, answer = brain_game.start_round() print('Question: {0}'.format(question)) player_answer = prompt.string('Your answer: ') if player_answer != answer: print( "'{0}' is wrong answer ;(. Correct answer was '{1}'".format( player_answer, answer, ), ) print("Let's try again, {0}!".format(name)) break print('Correct!') else: print('Congratulations, {0}!'.format(name))
def engine(description, game_data): """Make for game logic. Args: description: of game game_data: function from game that generate tuple with question and right answer """ print('Welcome to the Brain Games!') name = prompt.string('May I have your name? ') print(f'Hello, {name}!') print(description + '\n') count = 0 while count < number_of_games: question, right_answer = game_data() print(f'Question: {question}') answer = prompt.string('Your answer: ') if answer == right_answer: print('Correct!') count += 1 else: print( f"'{answer}' is wrong answer ;(. Correct answer was '{right_answer}'." ) print(f"Let's try again, {name}!") break else: print(f'Congratulations, {name}')
def run(module): # Welcome to the game text: print('\nWelcome to the Brain Games!') module.welcome() # Asking name and printing the greet: name = prompt.string('May i have your name: ') print('Hello, {}!\n'.format(name)) # Template for incorrect text: incorrect_text = 'is wrong answer. Correct answer was' # Generating 3 answers to win. Game stops if answer is incorrect: for lvl_counter in range(LVL_NUMBERS): # Unpacking tuple with question and right answer from logic file que_and_right = module.question_and_answer() (question, right) = que_and_right # Asking the question and taking player's answer: print(question) guess = prompt.string('Your answer: ') # Condition compares player's answer and right result and print result: if guess == right: print('Correct!\n') else: print('\n{} {} {}.'.format(guess, incorrect_text, right)) print("Let's try again, {}.".format(name)) break else: print('Congratulations, {}!\n'.format(name))
def run(game): print("Welcome to the Brain Games!") print(game.GAME_DESCRIPTION) print() name = prompt.string("May I have your name? ") print("Hello, {}!".format(name)) print() question_number = 1 while question_number <= MAX_NUMBER_OF_QUESTIONS: question, correct_answer = game.generate_task() print("Question: {}".format(question)) given_answer = prompt.string("Your answer: ") if given_answer != correct_answer: result = "'{}' is wrong answer ;(. Correct answer was '{}'." print(result.format(given_answer, correct_answer)) return print("Correct!") question_number += 1 print("Congratulations, {}!".format(name))
def engine(game): # noqa: WPS213 """engine.""" print('Welcome to the Brain Games!') print(game.DESCRIPTION) print() name = prompt.string('May I have your name? ') print('Hello, {name}!'.format(name=name)) print() for _ in range(NUMBER_OF_ROUNDS): question, answer = game.generate_round_data() print('Question: {question}'.format(question=question)) user_answer = prompt.string('Your answer: ') if user_answer != answer: print( "Answer '{wrong}' is wrong answer ;(. " "Correct answer was '{correct}'.".format( # noqa: WPS326 wrong=user_answer, correct=answer, ), ) print("Let's try again, {name}!".format(name=name)) break print('Correct!') else: print('Congratulations, {name}!'.format(name=name))
def start_game(game=None): print("Welcome to the Brain Games!") user_name = prompt.string("May I have your name? ") print(f"Hello, {user_name}!") if game is not None: print(game.DESCRIPTION) round_number = 0 while round_number < MAX_ROUND: question, right_answer = game.prepare_round() print(f"Question: {question}") answer = prompt.string("Your answer: ") round_number += 1 if answer != right_answer: print( f"'{answer}' is wrong answer ;(.", f"Correct answer was '{right_answer}'.", ) print(f"Let's try again, {user_name}!") return else: print("Correct") print(f"Congratulations, {user_name}!")
def play(game): print('Welcome to the Brain Games!') # game description print(game.DESCRIPTION) # ask player name name = prompt.string('May i have your name: ') print('Hello, {}!'.format(name)) incorrect_text = 'is wrong answer. Correct answer was' for level in range(MAX_LEVEL): question, correct_answer = game.get_question_and_answer() print(question) user_answer = prompt.string('Your answer: ') if user_answer == correct_answer: print('Correct!') else: print("'{}' {} '{}'.".format(user_answer, incorrect_text, correct_answer)) print("Let's try again, {}.".format(name)) break else: print('Congratulations, {}!'.format(name))
def play(instructions, get_round): """Start game. Args: instructions (str): Instructions for game. get_round (function): Function returning a question and correct answer. """ print('Welcome to the Brain Games!') user_name = prompt.string('May I have your name? ') print('Hello, {0}!'.format(user_name)) print(instructions) answers_count = 0 while answers_count < GOAL: question, correct_answer = get_round() print('Question: {0}'.format(question)) answer = prompt.string('Your answer: ') if answer != correct_answer: print(( "'{0}' is wrong answer ;(. Correct answer was '{1}'." ).format(answer, correct_answer), ) print("Let's try again, {0}!".format(user_name)) break print('Correct!') answers_count += 1 else: print('Congratulations, {0}!'.format(user_name))
def engine(game): import prompt print('Welcome to the Brain Games!') name = prompt.string('May I have your name? ') print('Hello, {}!'.format(name)) print() print(game.GREETING) print() i = 1 while i <= roundscount: question, result = game.generate_data() print('Question: {}'.format(question)) answer = prompt.string('Your answer: ') if answer == result: if i == roundscount: print('Correct!') print('Congratulations, {}!'.format(name)) return else: print('Correct, {}!'.format(name)) i += 1 else: print("'{}'".format(answer) + " is wrong answer ;(.") print("Correct answer was " + "'{}'".format(result)) print("Let's try again, {}!".format(name)) return
def engine(game): """ Run a code. Args: game: game atributes """ print('Welcome to the Brain Game!') name = prompt.string('May I have your name? ') print('Hello, {0}!'.format(name)) print(game.RULE) for _ in range(ROUNDS_COUNT): question, answer = game.generate_question_answer() print('Question:', question) player_answer = prompt.string('Your answer: ') if answer != player_answer: print( "'{0}', 'is wrong answer ;(. Correct answer was '{1}'.".format( player_answer, answer, ), ) print("Let's try again, {0}!".format(name)) return print('Correct!') print('Congratulations, {0}!'.format(name))
def run(game): player_name = prompt.string("May I have your name? ") print("Hello, {}!".format(player_name)) print(game.GAME_DESCRIPTION) for _ in range(TOTAL_QUESTIONS): game_question, correct_answer = game.generate_task() print("Question: {}".format(game_question)) player_answer = prompt.string("Your answer: ") if player_answer != correct_answer: print("'{}' is wrong answer ;(. Correct answer was '{}'.".format( player_answer, correct_answer)) print("Let's try again, {}!".format(player_name)) return print("Correct!") print("Congratulations, {}".format(player_name))
def main(): count = 0 correct_answer = 0 while count <= 0: numb = random_number() print('Question: ' + str(numb)) answer = prompt.string('Your answer: ') if numb % 2 == 0 and answer == 'yes': correct() count += 1 correct_answer += 1 elif numb % 2 == 1 and answer == 'no': correct() count += 1 correct_answer += 1 elif numb % 2 == 0 and answer == 'no': wrong_answer1() count += 3 #завершает игру elif numb % 2 == 1 and answer == 'yes': wrong_answer2() count += 3 #завершает игру else: wrong_input() if correct_answer == 3: print("Congratulations, {name}")
def logic(instruction, generator, check): # noqa: WPS210 """Start the game-process. Args: instruction: print instruction for the contest. generator: generator of questions. check: check-function. """ greeting() instruction() name = welcome_user() questions = generator(ROUNDS) amount = 1 while amount < (ROUNDS + 1): question = questions[amount - 1] print('Question: {q}'.format(q=question)) answer = prompt.string('Your answer: ') correct_answer = give_correct_answer(check, question) if answer == correct_answer: print('Correct!') amount += 1 else: print('{a} is wrong answer ;(. Correct answer was {b}'.format( a=answer, b=correct_answer, )) break if amount > ROUNDS: print('Congratulations, {n}!'.format(n=name))
def generate_questions(name, right_answer_count=0): """ Generate question and check his right. Parameters: name (str): user name right_answer_count (int): integer number meaning right answer count """ if right_answer_count == 3: print('Congratulations,', name, '!') return first_num = randint(1, 100) second_num = randint(1, 100) right_answer = find_max_common_divisor(first_num, second_num, name) if right_answer == 'uncorrect elements was generated': generate_questions(name, right_answer_count) else: print('Question:', first_num, second_num) answer = prompt.string('Your answer? ', empty=False) if check_right(right_answer, answer): print('Correct!') right_answer_count += 1 generate_questions(name, right_answer_count) else: return
def greeting(game_name=None): print('Welcome to the Brain Games!') _, _, phrase = game_name() print(phrase) name = string('May I have your name? ') print(f'Hello, {name}!') return name
def play(game): """ Plays a game with user in cli. Args: game (brain_games.games): Game interface. """ greet_user() name = ask_name() welcome_user(name) right_answers_count = 0 print(game.RULES) while right_answers_count < ANSWERS_TO_WIN_COUNT: question, correct_answer = game.get_question_and_answer() print('Question: {0}'.format(question)) user_answer = prompt.string('Your answer: ') if correct_answer != user_answer: print( _CORRECT_ANSWER_TEMPLATE.format( user_answer, correct_answer, ), ) print("Let's try again, {0}!".format(name)) return print('Correct!') right_answers_count += 1 print('Congratulations, {0}!'.format(name))
def get_username(): """Get name from input. Returns: user_name """ return prompt.string('May I have your name? ')
def test_string(input_patch): input_patch.do("foo123") assert prompt.string() == "foo123"
def test_string(): assert prompt.string(empty=True) is None
# check db is existing if args.mode != MODE_INIT: if db.get_config('initialized') is None: prompt.fail('Please initialize database first (soma init)') exit(1) if args.mode == MODE_INIT: if db.get_config('initialized') is not None: prompt.fail('Database is already initialized!') exit(1) else: try: current_user = pwd.getpwuid(os.getuid()).pw_name soma_user = prompt.string('Please provide soma master username (blank to use `%s`): ' % current_user, default=current_user, pattern=prompt.Validators.username) soma_path = prompt.directory('Directory to create problems (blank to use `/home`): ', default='/home') db.create_db(soma_user, soma_path) prompt.success('Database is successfully initialized') except Exception as err: prompt.fail('Failed to create database') prompt.show(err) exit(1) elif args.mode == MODE_ADD: # TODO: prevent injection # TODO: revert changes on fail check_root() # common config prob_source = prompt.string('Problem source: ', pattern=prompt.Validators.no_space) prob_name = prompt.string('Problem name: ', pattern=prompt.Validators.no_space)