go_winter_work_2025/python/main.py
2025-01-25 09:12:29 +03:00

85 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()