示例#1
0
def run(game):
    name = cli.run()
    print(game.QUESTION)

    for _ in range(QUESTION_COUNT):
        question, right_answer = game.main()

        print("Question: {}".format(question))

        answer = cli.answer()

        if right_answer is True:
            right_answer = "yes"

        if right_answer is False:
            right_answer = "no"

        if answer != right_answer:
            template = "\n{} is wrong answer ;(. Correct answer was {}"
            print(template.format(answer, right_answer))
            print("Let's try again, {}".format(name))
            break

        print("Correct!\n")

    else:
        print("Congratulations, {}".format(name))
示例#2
0
def brain_progression():
    name = cli.run(
        "What number is missing in the progression?"
    )
    n = 0
    while n < 3:
        num_list = []
        r_num1 = randint(1, 10)
        delta = randint(1, 10)
        list_range = randint(5, 10)
        i = 0
        while i < list_range:
            num_list.append(r_num1)
            r_num1 += delta
            i += 1
        right_num = choice(num_list)
        num_index = num_list.index(right_num)
        print_list = num_list.copy()
        print_list[num_index] = '..'
        print_list = ' '.join(str(e) for e in print_list)
        print('Question: {}'.format(print_list))
        answer = prompt.string('Your answer: ')
        if answer == str(right_num):
            n += 1
            print('Correct!')
        else:
            print(
                "'{}' is wrong answer ;(."
                " Correct answer was '{}'\nLet's try again, {}!"
                .format(answer, right_num, name))
            break
    if n == 3:
        print('Congratulations, {}!'.format(name))
示例#3
0
def run(game):
    score = 0
    print('Welcome to the Brain Games!')
    print(game.DESCRIPTION)
    print('')
    name = cli.run()
    final_score = 3
    while score < final_score:
        question, correct = game.round()
        print('Question: ' + question)
        answer = prompt.string('Your answer: ')
        if answer != correct:
            print(f"'{answer}' is wrong answer ;(. Correct answer "
                  f"was '{correct}'. Let's try again, {name}!")
            break
        score += 1
        print('Correct!')
    if score == final_score:
        print(f'Congratulations, {name}!')
def brain_prime():
    name = cli.run(
        "Answer 'yes' if given number is prime. Otherwise answer 'no'."
    )
    n = 0
    while n < 3:
        r_num1 = randint(1, 100)
        print('Question: {}'.format(r_num1))
        user_answer = prompt.string('Your answer: ')
        right_answer = is_even(r_num1)
        if user_answer == str(right_answer):
            n += 1
            print('Correct!')
        else:
            print(
                "'{}' is wrong answer ;(."
                " Correct answer was '{}'.\nLet's try again, {}!"
                .format(user_answer, right_answer, name))
            break
    if n == 3:
        print('Congratulations, {}!'.format(name))
示例#5
0
def brain_gcd():
    name = cli.run(
        "Find the greatest common divisor of given numbers."
    )
    n = 0
    while n < 3:
        r_num1 = randint(1, 100)
        r_num2 = randint(1, 100)
        print('Question: {} {}'.format(r_num1, r_num2))
        answer = prompt.string('Your answer: ')
        right_answer = calc_gcd(r_num1, r_num2)
        if answer == str(right_answer):
            n += 1
            print('Correct!')
        else:
            print(
                "'{}' is wrong answer ;(."
                " Correct answer was '{}'\nLet's try again, {}!"
                .format(answer, right_answer, name))
            break
    if n == 3:
        print('Congratulations, {}!'.format(name))
示例#6
0
def brain_calc():
    name = cli.run("What is the result of the Expression?")
    n = 0
    while n < 3:
        r_num1 = randint(1, 10)
        r_num2 = randint(1, 10)
        operation = {
            '{} + {}'.format(r_num1, r_num2): add(r_num1, r_num2),
            '{} - {}'.format(r_num1, r_num2): sub(r_num1, r_num2),
            '{} * {}'.format(r_num1, r_num2): mul(r_num1, r_num2),
        }
        r = choice(list(operation.keys()))
        print('Question: {}'.format(r))
        answer = prompt.string('Your answer: ')
        if answer == str(operation[r]):
            n += 1
            print('Correct!')
        else:
            print("'{}' is wrong answer ;(."
                  " Correct answer was '{}'\nLet's try again, {}!".format(
                      answer, operation[r], name))
            break
    if n == 3:
        print('Congratulations, {}!'.format(name))
示例#7
0
def main():
    run(prime)
示例#8
0
def main():
    run(progression)
示例#9
0
def main():
    print('Welcome to the Brain Games!')
    print()
    cli.run()
示例#10
0
def main():
    run(gcd)
示例#11
0
def main():
    run(calc)
示例#12
0
def main():
    cli.run()
示例#13
0
def main():
    cli.welcome()
    cli.run()
示例#14
0
def main():
    run(even)
示例#15
0
def main():
    run()
示例#16
0
def main():
    greet()
    run()