Advertisement
Guest User

Guess the Word

a guest
Jan 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import random
  2. a = input("Choose a difficulty \n \
  3. Easy-10 Lives \n \
  4. Medium-7 Lives \n \
  5. Hard-5 Lives \n \
  6. Choose a difficulty: ")
  7. a = a.lower()
  8. if a in {"easy", "medium", "hard"}:
  9.     print("Difficulty Selected")
  10. else:
  11.     print("Invalid Input!")
  12. if a == 'easy':
  13.     print("You have 10 lives left.")
  14.     lives = 10
  15. if a == 'medium':
  16.     print("You have 7 lives left.")
  17.     lives = 7
  18. if a == 'hard':
  19.     print("You have 5 lives left.")
  20.     lives = 5
  21. words = ['fairy', 'birds', 'doggy', 'frogs', 'phone', 'green', 'hello', ] #Dont put your nose where it doesnt belong
  22. secretword = random.choice(words)
  23. clue = list('?????')
  24. heart = u'\u2764'
  25. guess_correctly = False
  26.  
  27. def update_clue(guessed_letter, secretword, clue):
  28.     index = 0
  29.     while index < len(secretword):
  30.         if guessed_letter == secretword[index]:
  31.             clue[index] = guessed_letter
  32.         index = index + 1
  33.  
  34. while lives > 0:
  35.     print(clue)
  36.     print('Lives Left: ' + heart * lives)
  37.     guess = input('Guess a letter of the entire phrase!: ')
  38.    
  39.     if guess == secretword:
  40.         guess_correctly = True
  41.         break
  42.    
  43.     if guess in secretword:
  44.         update_clue(guess, secretword, clue)
  45.     else:
  46.         print('Incorrect! You lost a life!')
  47.         lives = lives - 1
  48.  
  49. if guess_correctly == True:
  50.     print('You Won!  The secret word was ' + secretword)
  51. else:
  52.     print('You lost! The secret word was ' + secretword)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement