6. Guess the word

Link to Replit (fork it to duplicate)

Example

print("Welcome to guess the word!")

from random_word import RandomWords
r = RandomWords()

# Return a single random word
word = r.get_random_word()

#word = "secret"
guesses = []
complete = False
count = 0

while not complete:
  count += 1

  guess = input("Guess a letter: ")
  guesses.append(guess)

  currentWord = ""
  for letter in word:
    if letter in guesses:
      currentWord += letter
    else:
      currentWord += "_"

  print(currentWord)
  if currentWord == word:
    complete = True
    print("Congratulations! You guessed the word " + word + " in " + str(count) + " guesses!")

Summary

In this video, the speaker discusses creating a game called Guess the Word, similar to Hangman, using Python programming concepts. They cover fundamentals like if-else statements, loops, and user input. The game involves guessing letters to uncover a secret word. The speaker demonstrates coding steps, such as initializing variables, storing guesses in a list, and implementing a while loop to continue the game until completion. They explain different loop options based on difficulty levels and emphasize a step-by-step coding approach to ensure functionality. The video provides a hands-on tutorial for beginners to practice coding logic and game development in Python.