From 28913baa5e0bf5cc82ddd98744b2247020c65820 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 1 May 2025 19:58:37 +0300 Subject: [PATCH] Adding an increase in difficulty level --- Short_plan | 5 +++++ main.py | 55 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Short_plan b/Short_plan index 5c77435..7f24e19 100644 --- a/Short_plan +++ b/Short_plan @@ -11,3 +11,8 @@ 5) Создание цикла while для ввода попыток 6) Создание цикла while для анализа попытки и вывода подсказки + +Идеи: + +1) Добавить уровни сложности, с повышением которых будет + увеличиваться длина загаданного слова и уменьшаться количество попыток diff --git a/main.py b/main.py index 459e802..3d3d3ad 100644 --- a/main.py +++ b/main.py @@ -8,44 +8,57 @@ def create_secret_num(guess_num): random.shuffle(digits) return ''.join(digits[:guess_num]) -def attempt_check(attemt): +def attempt_check(attemt, secret_num): clue = [] for i in range(len(attemt)): - if attemt[i] == attemt[i]: + if attemt[i] == secret_num[i]: clue.append("Fermi") - if attemt[i] in attemt: + elif attemt[i] in secret_num: clue.append("Pico") - return ' '.join(clue) if clue else 'Bagle' + sorted(clue) + return ' '.join(clue) if clue else 'Bagels' + +def game(max_nam, guess_num): -def game(): - secret_num = create_secret_num(guess_num) print("I meade a number.") attemt_num = 1 - - while max_nam >= attemt_num: - - attemt = '' - while len(attemt) != guess_num or not attemt.isdecimal(): - print(f"Attemt № {attemt_num}") # Вывод информации о том, сколько попыток сделал игрок - attemt = input("> ") - - if secret_num == attemt: - print("You win!") + level = 1 + while True: + if max_nam <= attemt_num: break + if level != 1: + max_nam += 2 + guess_num += 1 + attemt_num = 1 + secret_num = create_secret_num(guess_num) - print(attempt_check(attemt)) # А вот и подсказка + while max_nam >= attemt_num: - attemt_num += 1 + attemt = '' + print(f"You have {max_nam} attempt and {guess_num}-digit number") + while len(attemt) != guess_num or not attemt.isdecimal(): + print(f"Attemt {attemt_num}, Level {level}") # Вывод информации о том, сколько попыток сделал игрок + attemt = input("> ") + + if secret_num == attemt: + print("You win!") + print("Next level...") + break + + print(attempt_check(attemt,secret_num)) # А вот и подсказка + + attemt_num += 1 + level += 1 print("You're done trying") print(f"The hiden numbers is {secret_num}") + def main(): while True: - game() - answer = input("You want repeat the game?> ").lower() - if answer == 'no': + game(max_nam, guess_num) + if input("You want repeat the game?> ").lower().startswith('n'): print("Thanks for playing") break