Advertisement
biswasrohit20

scramble

Apr 21st, 2021
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. words = ("apple", "banana", "cherry")
  5. wordChoice = random.choice(words)
  6. correct = wordChoice
  7. scramble = ""
  8.  
  9. while wordChoice:
  10. position = random.randrange(len(wordChoice)) # select a random letter in the word
  11. scramble += wordChoice[position] # add the random letter to our new variable "scramble"
  12. wordChoice = wordChoice[:position] + wordChoice[(position + 1):]
  13.  
  14. print("Welcome to The Unscramble Game.")
  15. print()
  16. print(scramble)
  17. print()
  18. userguess = input("Type in your guess, hit y for a hint or x to give up ")
  19. userguess = userguess.lower()
  20. score = 10
  21. hint = range(len(scramble))
  22.  
  23. while True:
  24. if userguess == correct:
  25. print(f'Well done!!! Your score is {score}')
  26. break
  27. elif userguess == 'y':
  28. x = random.choice(hint)
  29. print(f'{correct[x]} is the "{x + 1}" letter')
  30. score -= 2
  31. userguess = input("Type in your guess, hit y for a hint or x to give up ")
  32. userguess = userguess.lower()
  33.  
  34. elif userguess == 'x':
  35. print("You gave up. Better luck next time")
  36. break
  37.  
  38. else:
  39. print("Sorry that is not correct")
  40. score -= 2
  41. userguess = input("Type in your guess, hit y for a hint or x to give up ")
  42. userguess = userguess.lower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement