def run(game): """Launch games. Args: game: str Returns: Return query to player. """ print('Welcome to the Brain Games!') # noqa: WPS421 player_name = cli.welcome_user('May I have your name? ') print('Hello, {a}!'.format(a=player_name)) # noqa: WPS421 print(game.DESCRIPTION) # noqa: WPS421 index = 0 while index < 3: (question, true_answer) = (game.generate_round()) # noqa: WPS421 answer_of_player = cli.welcome_user(( 'Question: {a}\nYour answer: ').format(a=question)) if answer_of_player == true_answer: print('Correct!') # noqa: WPS421 else: print( # noqa: WPS421 ("'{a}' is wrong answer ;). Correct answer was '{b}'." ).format(a=answer_of_player, b=true_answer)) return print( # noqa: WPS421 "Let's try again, {a}!".format(a=player_name), ) index += 1 return print( # noqa: WPS421 'Congratulations, {a}!'.format(a=player_name))
def maingcd(): """Do something interesting. # noqa: DAR101 username """ welcome_user() print('Find the greatest common divisor of given numbers.') username = welcome_user1() good = 0 while good < 3: number1 = randomnumber() number2 = randomnumber() first = number1 second = number2 while first != 0 and second != 0: if first > second: first %= second else: second %= first gcd = first + second answer = question(('{} {}'.format(number1, number2))) if answer == str(gcd): goodanswer() good += 1 else: wrong_answer(username, answer, gcd) finish_game(username)
def run_game(rules, game): """ Run game engine. Parameters: rules: game rules, will be displayed to the user at the beginning. game: (question, answer) tuple. """ welcome_user() name = ask_user_name() print(rules) win_count = 0 while win_count < 3: (question, answer) = game() print(f'Question: {question}') user_answer = prompt.string('Your answer: ') if user_answer == answer: print('Correct!') win_count += 1 else: print( f'{user_answer} is wrong answer ;(. Correct answer was {answer}.' ) # noqa: E501 print(f"Let's try again, {name}!") return print(f'Congratulations, {name}!')
def mainprime(): """Do something interesting. # noqa: DAR101 username """ welcome_user() print('Answer "yes" if given number is prime. Otherwise answer "no".') username = welcome_user1() good = 0 while good < 3: number = randomnumber() if number >= 2: index = 2 res = 'yes' while index < number: if abs(number) % index == 0: res = 'no' index = number else: index += 1 else: res = 'no' answer = question(number) if answer == res: goodanswer() good += 1 else: wrong_answer(username, answer, res) finish_game(username)
def mainprogression(): """Do something interesting. # noqa: DAR101 username """ welcome_user() print('What number is missing in the progression?') username = welcome_user1() good = 0 while good < 3: startprog = randomnumber() stepprog = random.randint(1, 10) stopprog = startprog + stepprog * 10 prog = (list(range(startprog, stopprog, stepprog))) index = random.randint(0, 9) minusnumber = prog[index] prog[index] = '..' number = 0 prog1 = '' while number < 10: prog1 = '{} {} '.format(prog1, str(prog[number])) number += 1 answer = question(('{}'.format(prog1))) if answer == str(minusnumber): goodanswer() good += 1 else: wrong_answer(username, answer, minusnumber) finish_game(username)
def maincalc(): """Do something interesting. # noqa: DAR101 username """ welcome_user() print('What is the result of the expression?') username = welcome_user1() good = 0 while good < 3: number1 = randomnumber() number2 = randomsymbol() number3 = randomnumber() if number2 == '*': number = number1 * number3 else: number = number1 + number3 answer = question(('{} {} {}'.format(number1, number2, number3))) if answer == str(number): goodanswer() good += 1 else: wrong_answer(username, answer, number) finish_game(username)
def main(): """ Program start. Parameters are missing. Returns: None """ welcome_user()
def main(): """ Represent game inreface. Returns: None """ print('Welcome to the Brain Games!') welcome_user()
def run(game): """ Engine of brain games. Parameters: game (module): module of the game to run Returns: None if answer is incorrect """ print('Welcome to the Brain Games!') print(game.RULES) print() username = welcome_user() for _ in range(ROUNDS_COUNT): # NOQA WPS122 question, correct = game.generate_conditions() print('Question: {0}'.format(question)) answer = prompt.string('Your answer: ') if answer != str(correct): text = WRONG_ANSWER.format( answer=answer, correct=correct, name=username, ) print(text) return None print(CORRECT_ANSWER) print('Congratulations, {0}!'.format(username))
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 run(game): """ Run the game. Args: game: name of the module with game logic. """ print() print('Welcome to the Brain Games!') print(game.get_rules()) print() user_name = cli.welcome_user() count = 1 while count <= ROUNDS: question, correct_answer = game.get_q_and_a() print('Question: {q}'.format(q=question)) answer = input('Your answer: ') if answer == correct_answer: cli.approve_answer() else: cli.reject_answer(answer, correct_answer, user_name) break count += 1 else: cli.congratulate(user_name)
def main(): """Launch the calc game.""" # Greets user name = cli.welcome_user() # Write rules print('What is the result of the expression?') generate_questions(name)
def run(game=None): """Run game.""" print('Welcome to the Brain Games!') user_name = welcome_user() if game: print(game.DESCRIPTION) if game: engine(user_name, game.make_question)
def main(): """ Call to necessary functions. Returns: return (str): username """ print('Welcome to the Brain Games!') return welcome_user()
def main(): """Ask name user. Start Brain Games - brain-calc.""" print('Welcome to the Brain Games!') name = cli.welcome_user() print('What is the result of the expression?') check = calc.game() if check: print('Congratulations, {}!'.format(name)) else: print("Let's try again, {}!".format(name))
def main(): """Ask name user. Start Brain Games - brain-prime.""" print('Welcome to the Brain Games!') name = cli.welcome_user() print('Find the greatest common divisor of given numbers') check = find_nod.game() if check: print('Congratulations, {}!'.format(name)) else: print("Let's try again, {}!".format(name))
def main(): """Ask name user. Start Brain Games - brain-prime.""" print('Welcome to the Brain Games!') name = cli.welcome_user() print('Answer "yes" if the number is even, otherwise answer "no".') check = is_even.game() if check: print('Congratulations, {}!'.format(name)) else: print("Let's try again, {}!".format(name))
def run(game): cli.welcome_game(game.MESSAGE) user_name = cli.get_user_name() cli.welcome_user(user_name) counter = 0 while counter < ROUNDS_COUNT: question, answer = game.round() cli.print_question(question) player_answer = cli.get_player_answer() if answer != player_answer: cli.incorrect_answer(answer, player_answer, user_name) return cli.correct_answer() counter += 1 cli.print_congratulation(user_name)
def main(): """ Print welcome message then call welcome_user func. Returns: username (str): name choiced by user. """ print('Welcome to the Brain Games!') username = cli.welcome_user() print('Hello', username, '!') return username
def main(): """Brain even main function.""" separation = '' print('Welcome to the Brain Games!') name = welcome_user() print('Hello, ', name, '!', sep=separation) even_result = brain_even() if even_result == 0: print('Lets try again ', name, '!', sep=separation) elif even_result == 1: print('Congratulations, ', name, '!', sep=separation)
def maineven(): """Do something interesting. # noqa: DAR101 username """ welcome_user() print('Answer "yes" if number even otherwise answer "no".') username = welcome_user1() good = 0 while good < 3: task = randomnumber() answer = question(task) if (task % 2 == 0 and answer == 'yes') or (task % 2 == 1 and answer == 'no'): goodanswer() good += 1 elif task % 2 == 0: wrong_answer(username, answer, 'yes') else: wrong_answer(username, answer, 'no') finish_game(username)
def run(module): name = cli.welcome_user(module.SPEC_INFO) for turn in range(module.ROUNDS_NUMBER): question, right_answer = module.make_question_answer() guess = cli.get_answer(question) if not check_answer(guess, right_answer): cli.show_wrong_answer_message(name, guess, right_answer) break cli.show_correct_answer_message() else: cli.show_you_win_message(name)
def begin_game(game): name = welcome_user() print(game.DESCRIPTION) for i in range(3): temp = game.get_question_answer() if temp[0] is True: print('Correct!') else: print("""'{}' is wrong answer ;(. Correct answer was '{}'.\ """.format(temp[1], temp[2])) print("Let's try again, {}!".format(name)) break else: print('Congratulations, {}!'.format(name))
def run(game, rounds=3): cli.greet() name = cli.welcome_user(game.RULES) counter = 0 while counter < rounds: question, true_answer = game.get_game() user_answer = cli.request_answer(question) if user_answer != true_answer: cli.show_wrong_answer_message(user_answer, true_answer, name) break cli.show_right_answer_message() counter += 1 else: cli.show_win_game_message(name)
def main_flow(TASK): NAME = welcome_user() print(TASK) N = 0 while N < 3: (EXPRESSION, RESULT, TYPE_OF_ANSWER) = math() (GAME_RESULT, USER_ANSWER) = game(EXPRESSION, RESULT, TYPE_OF_ANSWER) N = game_flow(NAME, USER_ANSWER, RESULT, GAME_RESULT, N) if N == -1: break if N == -1: fault(USER_ANSWER, RESULT, NAME) else: felicitation(NAME)
def main(): user_name = cli.welcome_user() print("Find the greatest common divisor of given numbers.") for i in range(3): random_number_one = random.randint(1,50) random_number_two = random.randint(1,50) print("Question: {} {}".format(random_number_one, random_number_two)) answer = prompt.string("Your answer: ") right_answer = calc_gcd(random_number_one, random_number_two) if answer == str(right_answer): print("Correct!") else: cli.wrong_answer(answer, right_answer, user_name) return 0 print("Congratulations, {}!".format(user_name))
def run(game, rounds=3): """Template for brain game engine.""" print('Welcome to the Brain Games!') print(game.RULES) user_name = welcome_user() while rounds > 0: question, true_answer = game.play_round() print('Question: {0}'.format(question)) answer = ask('Your answer: ') if answer != true_answer: print(WRONG_SAMPLE.format(answer, true_answer, user_name)) break print('Correct!') rounds -= 1 else: print('Congratulations!')
def engine(module): name = welcome_user(module) i = 1 while i <= 3: question, chek_question = module.generation() print('Question: {}'.format(question)) answer = prompt.string('Your answer: ') if answer == chek_question: print('Correct!') else: print("""'{}' is wrong answer :(.Correct answer was '{}'. Let's try again, {}!""".format(answer, chek_question, name)) break i += 1 else: print('Congratulations, {}!'.format(name))
def engine(module): name = welcome_user() print(module.WELCOME) i = 1 while i <= COUNT: question, correct_answer = module.generation() print(f'Question: {question}') answer = prompt.string('Your answer: ') if answer == correct_answer: print('Correct!') else: print(f"'{answer}' is wrong answer ;(." f" Correct answer was '{correct_answer}'.") print(f"Let's try again, {name}!") return i += 1 print(f'Congratulations, {name}!')
def run(game, rounds=3): name = cli.welcome_user(game.GAME_RULES) counter = 0 while counter < rounds: question, correct_answer = game.start() print(question) answer = cli.user_answer() if correct_answer == answer: print('Correct!') counter = counter + 1 else: print("'{}' is wrong answer ;(." "Correct answer was '{}'.". format(answer, correct_answer)) print("Let's try again, {}!". format(name)) return print("Congratulations, {}!". format(name))