Guest User

Untitled

a guest
Dec 14th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. from random import randint
  2.  
  3. def checkWord(inputList, wordList, guess):
  4. correct = False
  5. for index, item in enumerate(wordList, start=0):
  6. if item == guess:
  7. correct = True
  8. inputList[index] = guess
  9. if correct == True:
  10. return inputList
  11. else:
  12. return correct
  13.  
  14. def chooseWord():
  15. file = open("input.txt", "r")
  16. fileInput = file.readlines()
  17. word = fileInput[randint(0, len(fileInput))]
  18. return(list(word)[:-1])
  19.  
  20. def blankList(wordList):
  21. blank = []
  22. for i in wordList:
  23. blank.append("_")
  24. return blank
  25.  
  26.  
  27. wordList = chooseWord()
  28. usedList = []
  29. inputList = blankList(wordList)
  30. wrongCount = 0
  31. while True:
  32. print(",".join(usedList))
  33. print(" ".join(inputList))
  34. print(str(wrongCount)+" attempts")
  35. userInput = raw_input("Enter your letter:")
  36. if len(userInput) == 1 and userInput not in usedList:
  37. usedList.append(userInput)
  38. output = checkWord(inputList, wordList, userInput)
  39. if output == False:
  40. wrongCount += 1
  41. else:
  42. inputList = output
  43. if wrongCount == 10:
  44. break
  45.  
  46. if inputList == wordList:
  47. print("YES")
  48. break
Add Comment
Please, Sign In to add comment