Advertisement
Roman9234

Untitled

Feb 8th, 2024 (edited)
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | Gaming | 0 0
  1. import random
  2.  
  3. def choose_word():
  4.     with open("words.txt", mode="r", encoding="utf-8") as file:
  5.         words = file.read().split("\n")
  6.         return random.choice(words)
  7.  
  8. secret_word = choose_word()
  9. tries = 5
  10. while tries != 0:
  11.     player_word = input("Введите слово: ")
  12.     alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
  13.     if len(player_word) != len(secret_word):
  14.         print("Вы должны ввести слово из 4 букв")
  15.         exit()
  16.  
  17.     bulls = 0
  18.     cows = 0
  19.     for i, letter in enumerate(secret_word):
  20.         if letter in player_word: # если буква из секретного слова есть в нашем
  21.             if secret_word[i] == player_word[i]:
  22.                 bulls+=1
  23.             else:
  24.                 cows+=1
  25.     print(f"В вашем слове {cows} коров и {bulls} быков")
  26.     tries -= 1
  27.     print(f"Осталось попыток: {tries}")
  28.     if tries == 0:
  29.         print(f"Вы проиграли. {secret_word} - загаданное слово")
  30.         break
  31.     if bulls == len(secret_word):
  32.         print("Вы отгадали слово! Ура!")
  33.         break
  34.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement