Advertisement
Allena_Gorskaya

Виселица

Feb 12th, 2019
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import random
  2. lives = 9
  3. words = ['пицца', 'выдра', 'кошка', 'питон']
  4. secret_word = random.choice(words)
  5. secret = ['?'] * 5
  6. heart = u'\u2764'
  7. correct_ans = False
  8.  
  9. while lives > 0:
  10.     print(secret)
  11.     print('Осталось жизней: ' + heart * lives)
  12.     ans = input('Угадайте букву или слово целиком\n')
  13.     if ans == secret_word:
  14.         correct_ans = True
  15.         break
  16.     if ans in secret_word:
  17.         for index in range(5):
  18.             if secret_word[index] == ans:
  19.                 secret[index] = ans
  20.         if not '?' in secret:
  21.             correct_ans = True
  22.             break
  23.         else:
  24.             print('Вы угадали одну букву')
  25.     else:
  26.         print('Неправильно! Вы теряете жизнь')
  27.         lives = lives - 1
  28.  
  29. if correct_ans == True:
  30.     print('Победа!')
  31. else:
  32.     print('Вы проиграли! Было загадано слово', secret_word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement