Get the answers you need at Westonci.ca, where our expert community is dedicated to providing you with accurate information. Our platform provides a seamless experience for finding reliable answers from a knowledgeable network of professionals. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.

import random
def loadWordList(path):
lines=[]
try:
fileObj = open (path,"r")
for line in fileObj:
lines.append(line)
except:
print(f"Error with file: {path}")
return None
return lines
def guessWord(mWord):
asteriskWord = "*" * (len(mWord) - 1)
# convert each character in asteriskWord to a list
asteriskList = list(asteriskWord)

# repeat until all * have been converted to their matching letter
while ("*" in asteriskWord):
letterFound = False
print("\n\n")
print (asteriskWord)
letter = input("Enter a letter to guess --> ")
letter = letter[0]
for i in range(len(asteriskList)+1):
if letter == mWord[i]:
asteriskList[i] = letter
letterFound = True
if not letterFound:
print (f"{letter} is not in the mystery word")
# convert list back to a string
asteriskWord = "".join(asteriskList)
print(f"\n\nCongradulations: you guessed the word {mWord}")
def main():
wordList = loadWordList("c:\\user\\sandy\\wordlist.txt")
mysteryWord = wordList[random.randrange(0,len(wordList))]
guessWord(mysteryWord)
main()

I need to fix the bugs and also add the word "bomb" to the code as a mystery word


Import Random Def LoadWordListpath Lines Try FileObj Open Pathr For Line In FileObj Linesappendline Except PrintfError With File Path Return None Return Lines D class=

Sagot :

Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.