Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- words = ("apple", "banana", "cherry")
- wordChoice = random.choice(words)
- correct = wordChoice
- scramble = ""
- while wordChoice:
- position = random.randrange(len(wordChoice)) # select a random letter in the word
- scramble += wordChoice[position] # add the random letter to our new variable "scramble"
- wordChoice = wordChoice[:position] + wordChoice[(position + 1):]
- print("Welcome to The Unscramble Game.")
- print()
- print(scramble)
- print()
- userguess = input("Type in your guess, hit y for a hint or x to give up ")
- userguess = userguess.lower()
- score = 10
- hint = range(len(scramble))
- while True:
- if userguess == correct:
- print(f'Well done!!! Your score is {score}')
- break
- elif userguess == 'y':
- x = random.choice(hint)
- print(f'{correct[x]} is the "{x + 1}" letter')
- score -= 2
- userguess = input("Type in your guess, hit y for a hint or x to give up ")
- userguess = userguess.lower()
- elif userguess == 'x':
- print("You gave up. Better luck next time")
- break
- else:
- print("Sorry that is not correct")
- score -= 2
- userguess = input("Type in your guess, hit y for a hint or x to give up ")
- userguess = userguess.lower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement