Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def checkWord(inputList, wordList, guess):
- correct = False
- for index, item in enumerate(wordList, start=0):
- if item == guess:
- correct = True
- inputList[index] = guess
- if correct == True:
- return inputList
- else:
- return correct
- def chooseWord():
- file = open("input.txt", "r")
- fileInput = file.readlines()
- word = fileInput[randint(0, len(fileInput))]
- return(list(word)[:-1])
- def blankList(wordList):
- blank = []
- for i in wordList:
- blank.append("_")
- return blank
- wordList = chooseWord()
- usedList = []
- inputList = blankList(wordList)
- wrongCount = 0
- while True:
- print(",".join(usedList))
- print(" ".join(inputList))
- print(str(wrongCount)+" attempts")
- userInput = raw_input("Enter your letter:")
- if len(userInput) == 1 and userInput not in usedList:
- usedList.append(userInput)
- output = checkWord(inputList, wordList, userInput)
- if output == False:
- wrongCount += 1
- else:
- inputList = output
- if wrongCount == 10:
- break
- if inputList == wordList:
- print("YES")
- break
Add Comment
Please, Sign In to add comment