Skip to content

Commit

Permalink
even game complexity should be reduced
Browse files Browse the repository at this point in the history
Signed-off-by: hikarikumo <[email protected]>
  • Loading branch information
hikarikumo committed Dec 17, 2023
1 parent 30a2377 commit 6dcdf9e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ requires python >= 3.7

# CodeClimate Maintainability
[![Maintainability](https://api.codeclimate.com/v1/badges/d8d8ba9440c8786c2ccf/maintainability)](https://codeclimate.com/github/hikarikumo/python-project-lvl1/maintainability)
# CodeClimate test coverage
[![Test Coverage](https://api.codeclimate.com/v1/badges/d8d8ba9440c8786c2ccf/test_coverage)](https://codeclimate.com/github/hikarikumo/python-project-lvl1/test_coverage)
<!-- # CodeClimate test coverage
[![Test Coverage](https://api.codeclimate.com/v1/badges/d8d8ba9440c8786c2ccf/test_coverage)](https://codeclimate.com/github/hikarikumo/python-project-lvl1/test_coverage) -->
# travis ci
[![Build Status](https://travis-ci.com/hikarikumo/python-project-lvl1.svg?branch=master)](https://travis-ci.com/hikarikumo/python-project-lvl1)
# asciinema: brain-games brain-even
Expand Down
4 changes: 2 additions & 2 deletions brain_games/calc_game.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cli import greet_first, welcome_user
import random
import prompt
from cli import greet_first, welcome_user


OPERATIONS = {
Expand All @@ -25,7 +25,7 @@ def check_answer(question, answer, correct_answer):
print(f'Your answer: {answer}')
print('Correct!')
return True
print(f"'{answer}' is wrong answer ;(. Correct answer was '{correct_answer}'")
print(f"'{answer}' is a wrong answer ;(. Correct answer was '{correct_answer}'")
return False


Expand Down
2 changes: 1 addition & 1 deletion brain_games/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def main():


if __name__ == '__main__':
main()
main()
46 changes: 17 additions & 29 deletions brain_games/even_game.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# -*- coding:utf-8 -*-

"""Function declaration to verify the answers."""

import prompt
import random
import general_module
from cli import greet_first, welcome_user


def check_if_even(number):
"""Return true if even."""
if number % 2 == 0:
return True
return False
return number % 2 == 0

def even_question():
print("Answer 'yes' if number even otherwise answer 'no'.")

def even_wrong_answer(correct_answer):
print(f"'{correct_answer}' is wrong answer ;(. Correct answer was '{'no' if correct_answer == 'yes' else 'yes'}.")

def even_game():
"""
Expand All @@ -29,41 +27,31 @@ def even_game():
random_number = random.randint(0, 1000)
even_result = check_if_even(random_number)
print(random_number)
general_module.even_question()
answer = prompt.string()
while answer == 'yes':
if even_result:
even_question()
answer = prompt.string().lower() # Convert answer to lowercase for case-insensitive comparison
if answer in ['yes', 'no']:
if (answer == 'yes' and even_result) or (answer == 'no' and not even_result):
return True
general_module.even_wrong_answer_yes(answer)
even_wrong_answer(answer)
return False
while answer == 'no':
if not even_result:
return True
general_module.even_wrong_answer_no(answer)
else:
print("Invalid input. Please answer 'yes' or 'no'.")
return False


def even_game_logic(name):
"""Even game main logic."""
counter = 1
while counter <= 3:
for _ in range(3):
received_value = even_game()
if received_value:
general_module.correct_answer()
if counter == 3:
general_module.game_success_finish(name)
else:
if not received_value:
general_module.try_again(name)
break
counter += 1

general_module.correct_answer()

def main():
"""Run brain-even game."""
greet_first()
name = welcome_user()
even_game_logic(name)


if __name__ == '__main__':
main()
main()
17 changes: 0 additions & 17 deletions brain_games/general_module.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# -*- coding:utf-8 -*-

"""General games module."""



def correct_answer():
print('Correct!')

Expand All @@ -15,14 +9,3 @@ def game_success_finish(name):
def try_again(name):
print("Let's try again, ", name, "!", sep='')


def even_question():
print("Answer 'yes' if number even otherwise answer 'no'.")


def even_wrong_answer_yes(answer):
print("'" + answer + "'" + " is wrong answer ;(. Correct answer was 'no'.")


def even_wrong_answer_no(answer):
print("'" + answer + "'" + " is wrong answer ;(. Correct answer was 'yes'.")
2 changes: 0 additions & 2 deletions brain_games/scripts/brain_calc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding:utf-8 -*-

"""Main script for calc game."""


Expand Down

0 comments on commit 6dcdf9e

Please sign in to comment.