diff --git a/python/main.py b/python/main.py index 4648e70..fab4995 100644 --- a/python/main.py +++ b/python/main.py @@ -1 +1,84 @@ -print("Hello, World!") \ No newline at end of file +import random + +word_dict = { + "питон": "интерпритируемый язык программирования", + "голанг": "компилируемый язык программирования", +} + + +def game(): + word_number = random.randint(0, len(word_dict) - 1) + word = list(word_dict.keys())[word_number] + describe = word_dict[word] + guess = ['_' for _ in word] + value_guess = len(word) + + print(describe) + print(" ".join(guess)) + while value_guess > 0: + character = input("Введите букву: ") + if word.count(character) >= 1: + for index, value in enumerate(word): + if character == value: + guess[index] = value + else: + value_guess -= 1 + print(f"У вас осталось {value_guess} попыток") + if guess.count('_') == 0: + print(" ".join(guess)) + break + + print(" ".join(guess)) + else: + print(f"GAME OVER =(") + + + + +def run_game(): + game() + + +def save_game(): + pass + + +def load_game(): + pass + + +def exit_game(): + exit(0) + + +def menu(): + print( + """ + 1. Начать игру + 2. Сохранить + 3. Загрузить + 4. Выход + """ + ) + + +def read_selector(): + key = int(input(":")) + match key: + case 1: + run_game() + case 2: + save_game() + case 3: + load_game() + case 4: + exit_game() + + +def main(): + menu() + read_selector() + + +if __name__ == "__main__": + main()