Project 1758

by Srikrishnan R


Word guess project a standard one """ File: ------------------- Fill in this comment. """ import random def main(): """ To play the game, we first select the secret word for the player to guess and then play the game using that secret word. """ #list of words play_game() def play_game(): #words_list = ['sri', 'shobi'] words_list = ['CHIEF', 'JUNK', 'MANATEE', 'QUAGMIRE', 'REEF', 'SIMULTANEITY', 'PREETHU', 'DIVI', 'SUCCUMB', 'THEREIN', 'WARE', 'WOODY'] words = [x.lower() for x in words_list] #list to store wrong guessed_letters wrong_list = [] original_word = random.choice(words) guessed_word = [] print("The word now looks like this: ") for i in range(len(original_word)): guessed_word.append("__") print(*([i for i in guessed_word])) guesses = 8 # Initial number of guesses player starts with while guesses !=0: print(f"You have {guesses} guesses left") guessed_letter = input("Type a single letter here, then press enter: ") #check the user input not an alphabets if not guessed_letter.isalpha(): print('Guess only a letter') #check the user input more than single character elif (len(guessed_letter) > 1): print('Guess should only be a single character') #check that letter chosen by user is already guessed or not elif (guessed_letter in wrong_list): print('You have Already guessed this letter') #check if guessed_letter is matches with original_word if guessed_letter.isupper(): guessed_letter = guessed_letter.lower() if guessed_letter in original_word: for i in range(len(original_word)): if original_word[i] == guessed_letter: guessed_word[i] = original_word[i] print("That guess is correct.") else: """if guessed_letter is not in original_word prompt user for wrong chosen letter""" print("You Guessed wrong letter") guesses = guesses - 1 wrong_list.append(guessed_letter) guess_word = [i for i in guessed_word] guess_word = "".join(guess_word) if original_word == guess_word: print(f"Congratulations, the word is: {original_word} ") exit(0) # print the guessed word print(*([i for i in guessed_word])) if guesses == 0: if original_word != guessed_word: print(f"You lost the game ,The original Word was {original_word}") exit(1) # This provided line is required at the end of a Python file # to call the main() function. if __name__ == "__main__": main()