From bdce8718540c7bd90992e30009a4588453801717 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 11 Mar 2023 17:21:55 +0300 Subject: [PATCH 1/4] code according to PEP8 --- main.py | 46 +++++++++++++++++++++++++++++++--------------- pytest.ini | 2 +- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 1f468d66e..0ea7f7f9a 100644 --- a/main.py +++ b/main.py @@ -3,11 +3,16 @@ def attack(char_name, char_class): if char_class == 'warrior': - return (f'{char_name} нанёс урон противнику равный {5 + randint(3, 5)}') + return (f'{char_name} нанёс урон' + 'противнику равный {5 + randint(3, 5)}') if char_class == 'mage': - return (f'{char_name} нанёс урон противнику равный {5 + randint(5, 10)}') + return (f'{char_name} нанёс урон противнику' + f'равный {5 + randint(5, 10)}') if char_class == 'healer': - return (f'{char_name} нанёс урон противнику равный {5 + randint(-3, -1)}') + return (f'{char_name} нанёс урон' + 'противнику равный {5 + randint(-3, -1)}') + + def defence(char_name, char_class): if char_class == 'warrior': return (f'{char_name} блокировал {10 + randint(5, 10)} урона') @@ -15,17 +20,18 @@ def defence(char_name, char_class): return (f'{char_name} блокировал {10 + randint(-2, 2)} урона') if char_class == 'healer': return (f'{char_name} блокировал {10 + randint(2, 5)} урона') + + def special(char_name, char_class): - if char_class == 'warrior': - return (f'{char_name} применил специальное умение «Выносливость {80 + 25}»') + if char_class == 'warrior': + return (f'{char_name} применил специальное' + 'умение «Выносливость {80 + 25}»') if char_class == 'mage': return (f'{char_name} применил специальное умение «Атака {5 + 40}»') if char_class == 'healer': return (f'{char_name} применил специальное умение «Защита {10 + 30}»') - - def start_training(char_name, char_class): if char_class == 'warrior': print(f'{char_name}, ты Воитель — отличный боец ближнего боя.') @@ -34,7 +40,9 @@ def start_training(char_name, char_class): if char_class == 'healer': print(f'{char_name}, ты Лекарь — чародей, способный исцелять раны.') print('Потренируйся управлять своими навыками.') - print('Введи одну из команд: attack — чтобы атаковать противника, defence — чтобы блокировать атаку противника или special — чтобы использовать свою суперсилу.') + print('Введи одну из команд: attack — чтобы атаковать противника,' + 'defence — чтобы блокировать атаку противника или special' + '— чтобы использовать свою суперсилу.') print('Если не хочешь тренироваться, введи команду skip.') cmd = None while cmd != 'skip': @@ -47,18 +55,26 @@ def start_training(char_name, char_class): print(special(char_name, char_class)) return 'Тренировка окончена.' + def choice_char_class(): approve_choice = None char_class = None while approve_choice != 'y': - char_class = input('Введи название персонажа, за которого хочешь играть: Воитель — warrior, Маг — mage, Лекарь — healer: ') + char_class = input('Введи название персонажа, за которого хочешь' + 'играть: Воитель — warrior, Маг — mage,' + 'Лекарь — healer: ') if char_class == 'warrior': - print('Воитель — дерзкий воин ближнего боя. Сильный, выносливый и отважный.') + print('Воитель — дерзкий воин ближнего боя. Сильный, ' + 'выносливый и отважный.') if char_class == 'mage': - print('Маг — находчивый воин дальнего боя. Обладает высоким интеллектом.') + print('Маг — находчивый воин дальнего боя. Обладает высоким' + 'интеллектом.') if char_class == 'healer': - print('Лекарь — могущественный заклинатель. Черпает силы из природы, веры и духов.') - approve_choice = input('Нажми (Y), чтобы подтвердить выбор, или любую другую кнопку, чтобы выбрать другого персонажа ').lower() + print('Лекарь — могущественный заклинатель. Черпает силы из ' + 'природы, веры и духов.') + approve_choice = input('Нажми (Y), чтобы подтвердить выбор, или' + 'любую другую кнопку, чтобы выбрать ' + 'другого персонажа ').lower() return char_class @@ -72,6 +88,6 @@ def main(): print('Воитель, Маг, Лекарь') char_class = choice_char_class() print(start_training(char_name, char_class)) - -main() \ No newline at end of file + +main() diff --git a/pytest.ini b/pytest.ini index e03742bdc..9607971ea 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ -[pytest] +s[pytest] addopts = -vv -p no:cacheprovider \ No newline at end of file From b5a02164139a3ba518ccff68689c795c82c42e9c Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 11 Mar 2023 19:59:23 +0300 Subject: [PATCH 2/4] Add first commit --- .vscode/settings.json | 5 +++-- main.py | 22 +++++++++++----------- temp.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 temp.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 33fe63f7c..b40952230 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { - "python.linting.flake8Enabled": true, - "python.linting.enabled": true + "python.linting.flake8Enabled": false, + "python.linting.enabled": true, + "python.linting.mypyEnabled": true } \ No newline at end of file diff --git a/main.py b/main.py index 0ea7f7f9a..84c78aa31 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ from random import randint -def attack(char_name, char_class): +def attack(char_name: str, char_class: str) -> str: if char_class == 'warrior': return (f'{char_name} нанёс урон' 'противнику равный {5 + randint(3, 5)}') @@ -13,7 +13,7 @@ def attack(char_name, char_class): 'противнику равный {5 + randint(-3, -1)}') -def defence(char_name, char_class): +def defence(char_name: str, char_class: str) -> str: if char_class == 'warrior': return (f'{char_name} блокировал {10 + randint(5, 10)} урона') if char_class == 'mage': @@ -22,7 +22,7 @@ def defence(char_name, char_class): return (f'{char_name} блокировал {10 + randint(2, 5)} урона') -def special(char_name, char_class): +def special(char_name: str, char_class: str) -> str: if char_class == 'warrior': return (f'{char_name} применил специальное' 'умение «Выносливость {80 + 25}»') @@ -32,7 +32,7 @@ def special(char_name, char_class): return (f'{char_name} применил специальное умение «Защита {10 + 30}»') -def start_training(char_name, char_class): +def start_training(char_name: str, char_class: str) -> str: if char_class == 'warrior': print(f'{char_name}, ты Воитель — отличный боец ближнего боя.') if char_class == 'mage': @@ -44,7 +44,7 @@ def start_training(char_name, char_class): 'defence — чтобы блокировать атаку противника или special' '— чтобы использовать свою суперсилу.') print('Если не хочешь тренироваться, введи команду skip.') - cmd = None + cmd: str = None while cmd != 'skip': cmd = input('Введи команду: ') if cmd == 'attack': @@ -56,9 +56,9 @@ def start_training(char_name, char_class): return 'Тренировка окончена.' -def choice_char_class(): - approve_choice = None - char_class = None +def choice_char_class() -> str: + approve_choice: str = '' + char_class: str = '' while approve_choice != 'y': char_class = input('Введи название персонажа, за которого хочешь' 'играть: Воитель — warrior, Маг — mage,' @@ -78,15 +78,15 @@ def choice_char_class(): return char_class -def main(): +def main() -> str: print('Приветствую тебя, искатель приключений!') print('Прежде чем начать игру...') - char_name = input('...назови себя: ') + char_name: str = input('...назови себя: ') print(f'Здравствуй, {char_name}! ' 'Сейчас твоя выносливость — 80, атака — 5 и защита — 10.') print('Ты можешь выбрать один из трёх путей силы:') print('Воитель, Маг, Лекарь') - char_class = choice_char_class() + char_class: str = choice_char_class() print(start_training(char_name, char_class)) diff --git a/temp.py b/temp.py new file mode 100644 index 000000000..d57054d26 --- /dev/null +++ b/temp.py @@ -0,0 +1,35 @@ +# Тестовые данные. +TEST_DATA = [ + (44, 'success', True), + (16, 'failure', True), + (4, 'success', False), + (21, 'failure', False), +] + +BONUS = 1.1 +ANTIBONUS = 0.8 + +def add_rep(current_rep, rep_points, buf_effect): + current_rep += rep_points + if buf_effect: + return current_rep * BONUS + return current_rep + +def remove_rep(current_rep, rep_points, debuf_effect): + current_rep -= rep_points + if debuf_effect: + return current_rep * ANTIBONUS + return current_rep + +def main(duel_res): + current_rep = 0.0 + for rep, result, effect in duel_res: + if result == 'success': + current_rep = add_rep(current_rep, rep, effect) + if result == 'failure': + current_rep = remove_rep(current_rep, rep, effect) + return f'После {len(duel_res)} поединков, репутация персонажа — {current_rep:.3f} очков.' + + +# Тестовый вызов функции main. +print(main(TEST_DATA)) \ No newline at end of file From c768d4bf896c90b6fb0e819e6ea6b7c26a4c6a70 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 14 Mar 2023 19:31:29 +0300 Subject: [PATCH 3/4] add working version without classes --- .vscode/settings.json | 4 ++-- calc_and_win | 1 + doccc.py | 22 ++++++++++++++++++++++ graphic_arts | 1 + main.py | 19 ++++++++++++++++--- module1.py | 12 ++++++++++++ module2.py | 7 +++++++ pytest.ini | 2 +- 8 files changed, 62 insertions(+), 6 deletions(-) create mode 160000 calc_and_win create mode 100644 doccc.py create mode 160000 graphic_arts create mode 100644 module1.py create mode 100644 module2.py diff --git a/.vscode/settings.json b/.vscode/settings.json index b40952230..ecf9b4cee 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "python.linting.flake8Enabled": false, + "python.linting.flake8Enabled": true, "python.linting.enabled": true, - "python.linting.mypyEnabled": true + "python.linting.mypyEnabled": false } \ No newline at end of file diff --git a/calc_and_win b/calc_and_win new file mode 160000 index 000000000..612ec2436 --- /dev/null +++ b/calc_and_win @@ -0,0 +1 @@ +Subproject commit 612ec24361689126edf5f79548244f266700acaf diff --git a/doccc.py b/doccc.py new file mode 100644 index 000000000..acb717d9a --- /dev/null +++ b/doccc.py @@ -0,0 +1,22 @@ +from math import sqrt + + +message = 'Добро пожаловать в самую лучшую программу для вычисления ' \ + 'квадратного корня из заданного числа' +print(message) + + +def CalculateSquareRoot(Number): + """ Вычисляет квадратный корень""" + return sqrt(Number) + + +def calc(your_number): + if your_number <= 0: + return + print(f'Мы вычислили квадратный корень из введённого' + f' вами числа. Это будет: {CalculateSquareRoot(your_number)}') + + +print(message) +calc(25.5) diff --git a/graphic_arts b/graphic_arts new file mode 160000 index 000000000..53c35aaef --- /dev/null +++ b/graphic_arts @@ -0,0 +1 @@ +Subproject commit 53c35aaeff79bd1ed1c6dddea7838c510ca20b1c diff --git a/main.py b/main.py index 84c78aa31..9fd26e05a 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,12 @@ +"""Бла бла бла.""" from random import randint +from graphic_arts.start_game_banner import run_screensaver + + def attack(char_name: str, char_class: str) -> str: + """I love Danyuha.""" if char_class == 'warrior': return (f'{char_name} нанёс урон' 'противнику равный {5 + randint(3, 5)}') @@ -14,6 +19,7 @@ def attack(char_name: str, char_class: str) -> str: def defence(char_name: str, char_class: str) -> str: + """I am daun.""" if char_class == 'warrior': return (f'{char_name} блокировал {10 + randint(5, 10)} урона') if char_class == 'mage': @@ -23,6 +29,7 @@ def defence(char_name: str, char_class: str) -> str: def special(char_name: str, char_class: str) -> str: + """U are daun too.""" if char_class == 'warrior': return (f'{char_name} применил специальное' 'умение «Выносливость {80 + 25}»') @@ -33,6 +40,7 @@ def special(char_name: str, char_class: str) -> str: def start_training(char_name: str, char_class: str) -> str: + """Я всё сломала.""" if char_class == 'warrior': print(f'{char_name}, ты Воитель — отличный боец ближнего боя.') if char_class == 'mage': @@ -57,6 +65,7 @@ def start_training(char_name: str, char_class: str) -> str: def choice_char_class() -> str: + """Не беси.""" approve_choice: str = '' char_class: str = '' while approve_choice != 'y': @@ -78,11 +87,12 @@ def choice_char_class() -> str: return char_class -def main() -> str: +if __name__ == '__main__': + run_screensaver() print('Приветствую тебя, искатель приключений!') print('Прежде чем начать игру...') char_name: str = input('...назови себя: ') - print(f'Здравствуй, {char_name}! ' + rint(f'Здравствуй, {char_name}! ' 'Сейчас твоя выносливость — 80, атака — 5 и защита — 10.') print('Ты можешь выбрать один из трёх путей силы:') print('Воитель, Маг, Лекарь') @@ -90,4 +100,7 @@ def main() -> str: print(start_training(char_name, char_class)) -main() + # character_creation_module/main.py + + + diff --git a/module1.py b/module1.py new file mode 100644 index 000000000..eac9ce85e --- /dev/null +++ b/module1.py @@ -0,0 +1,12 @@ +def special_calculation(a, b): + return a + b - 2 + + +if __name__ == '__main__': + print('Модуль запущен') + print('Проверим работу функции') +# Запускается функция с разными значениями переменных a и b. +# Значения сравниваются с ожидаемым ответом. + print(5 == special_calculation(2, 5)) + print(5 == special_calculation(2, 2)) +print(4 == special_calculation(3, 3)) \ No newline at end of file diff --git a/module2.py b/module2.py new file mode 100644 index 000000000..3f32f1156 --- /dev/null +++ b/module2.py @@ -0,0 +1,7 @@ +# Из модуля module1.py импортируем функцию special_calculation. +from module1 import special_calculation + +print("Основной модуль") +# Производим расчёты. +coef = special_calculation(2, 5) +print(coef) \ No newline at end of file diff --git a/pytest.ini b/pytest.ini index 9607971ea..e03742bdc 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ -s[pytest] +[pytest] addopts = -vv -p no:cacheprovider \ No newline at end of file From 3cba8f44bd0db0f6b6f79cbab663efdb1870c78a Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 14 Mar 2023 19:36:55 +0300 Subject: [PATCH 4/4] add working version without classes --- doccc.py | 22 ---------------------- main.py | 9 +++------ 2 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 doccc.py diff --git a/doccc.py b/doccc.py deleted file mode 100644 index acb717d9a..000000000 --- a/doccc.py +++ /dev/null @@ -1,22 +0,0 @@ -from math import sqrt - - -message = 'Добро пожаловать в самую лучшую программу для вычисления ' \ - 'квадратного корня из заданного числа' -print(message) - - -def CalculateSquareRoot(Number): - """ Вычисляет квадратный корень""" - return sqrt(Number) - - -def calc(your_number): - if your_number <= 0: - return - print(f'Мы вычислили квадратный корень из введённого' - f' вами числа. Это будет: {CalculateSquareRoot(your_number)}') - - -print(message) -calc(25.5) diff --git a/main.py b/main.py index 9fd26e05a..8d0797099 100644 --- a/main.py +++ b/main.py @@ -92,15 +92,12 @@ def choice_char_class() -> str: print('Приветствую тебя, искатель приключений!') print('Прежде чем начать игру...') char_name: str = input('...назови себя: ') - rint(f'Здравствуй, {char_name}! ' + print(f'Здравствуй, {char_name}! ' 'Сейчас твоя выносливость — 80, атака — 5 и защита — 10.') print('Ты можешь выбрать один из трёх путей силы:') print('Воитель, Маг, Лекарь') char_class: str = choice_char_class() print(start_training(char_name, char_class)) + - - # character_creation_module/main.py - - - +# character_creation_module/main.py \ No newline at end of file