Advertisement
FiddleComputers

Shuffle Word game

Mar 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #coding: utf8
  2.  
  3. from random import randint
  4.  
  5. guessWord = str(raw_input("Enter the word to guess: "))
  6. tries = 0
  7.  
  8. shuffledGuessWord = ""
  9. keyUsed = []
  10.  
  11. while len(shuffledGuessWord) != len(guessWord):
  12.     keyAlreadyInArray = False
  13.     key = randint(0, len(guessWord)-1)
  14.     for i in range(0, len(keyUsed)):
  15.         if key == keyUsed[i]:
  16.             keyAlreadyInArray = True
  17.  
  18.     if not keyAlreadyInArray:
  19.         shuffledGuessWord += guessWord[key]
  20.         keyUsed.append(key)
  21.  
  22. print shuffledGuessWord
  23.  
  24. while str(raw_input("Enter the right word: ")) != guessWord:
  25.     tries += 1
  26.     print("Wrong word!")
  27.     print ("Try #"+str(tries))
  28.  
  29. print("You found the right word! It was indeed "+guessWord)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement