Posts

Showing posts with the label hangman

Hangman - 3 other versions (advanced)

Image
  #Step 4 import random stages = [''' +---+ | | O | /|\ | / \ | | ========= ''', ''' +---+ | | O | /|\ | / | | ========= ''', ''' +---+ | | O | /|\ | | | ========= ''', ''' +---+ | | O | /| | | | =========''', ''' +---+ | | O | | | | | ========= ''', ''' +---+ | | O | | | | ========= ''', ''' +---+ | | | | | | ========= '''] end_of_game = False word_list = ["aardvark", "baboon", "camel", "flower", "singapore", "alex" ] chosen_word = random.choice(word_list) word_length = len(chosen_word) #TODO-1: - Create a variable called 'lives' to keep track of the number of lives left. #Set ...

Hangman - 3 versions

Image
#very simple code - V1 import random word_list = ["aardvark", "baboon", "camel", "myblog", "abs"] chosen_word = random.choice(word_list) guess = input("Guess a letter? >> ").lower() for letter in chosen_word: if letter == guess: print("Right!") else: print("Wrong!")   #much more advanced code - V2 import random word_list = ["aardvark", "baboon", "camel"] chosen_word = random.choice(word_list) #Testing code print(f'Pssst, the solution is {chosen_word}.') display = [] word_length = len(chosen_word) for _ in range(word_length): display += "_" guess = input("Guess a letter: ").lower() for position in range(word_length): letter = chosen_word[position] #print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}") if letter == guess: display[position] = letter print(display...