From bd080ad882ccba61d8f0191421881817cc197686 Mon Sep 17 00:00:00 2001 From: hikarikumo Date: Sun, 17 Dec 2023 17:28:59 +0200 Subject: [PATCH] refactored main function calc_game for codeclimate complexitiy Signed-off-by: hikarikumo --- brain_games/calc_game.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/brain_games/calc_game.py b/brain_games/calc_game.py index 49628f5..51cf5b1 100644 --- a/brain_games/calc_game.py +++ b/brain_games/calc_game.py @@ -1,10 +1,8 @@ -# -*- coding:utf-8 -*- -"""Calc games function to ask questions and verify the answers.""" - import random import prompt from cli import greet_first, welcome_user + OPERATIONS = { 'summation': ('+', lambda x, y: x + y), 'subtraction': ('-', lambda x, y: x - y), @@ -43,16 +41,13 @@ def user_fail_message(name): def calc_game_logic(name): - counter = 1 - while counter <= 3: + for counter in range(1,3): operations = list(OPERATIONS.keys()) for operation in operations: if not play_game(operation): user_fail_message(name) return - if counter == 3: - print(f'Congratulations, {name}!') - counter += 1 + print(f'Congratulations, {name}!') def main():