Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def choose_word():
- with open("words.txt", mode="r", encoding="utf-8") as file:
- words = file.read().split("\n")
- return random.choice(words)
- secret_word = choose_word()
- tries = 5
- while tries != 0:
- player_word = input("Введите слово: ")
- alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
- if len(player_word) != len(secret_word):
- print("Вы должны ввести слово из 4 букв")
- exit()
- bulls = 0
- cows = 0
- for i, letter in enumerate(secret_word):
- if letter in player_word: # если буква из секретного слова есть в нашем
- if secret_word[i] == player_word[i]:
- bulls+=1
- else:
- cows+=1
- print(f"В вашем слове {cows} коров и {bulls} быков")
- tries -= 1
- print(f"Осталось попыток: {tries}")
- if tries == 0:
- print(f"Вы проиграли. {secret_word} - загаданное слово")
- break
- if bulls == len(secret_word):
- print("Вы отгадали слово! Ура!")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement