Lesson 6 - Word Guessing Game (Final Project)

In this final lesson we will be using our previous knowledge in functions and variables to create a Word Guessing Game! This simple game provides a clear example to the wide functionality of the Python language. ‚Äč Upon completion, please send a screenshot of your final project to our email to receive your completion certificate!

    import random
    name = input("What is your name? ")
    print("Hi,", name, "! Good luck!")
    words = ['python', 'computers', 'programming', 'dog', 'cat', 'math']
    word = random.choice(words)
    guesses = ''
    turns = 12
    while turns > 0:
      failed = 0
      for char in word:
          if char in guesses:
              print(char)
          else:
              print("-")
              failed += 1
      if failed == 0:
          print("You win!")
          print("The word is: ", word)
          break
      guess = input("Guess another letter: ")
      guesses += guess
      if guess not in word:
          turns -= 1
          print("Wrong")
          print("You have", turns, " guesses left")
          if turns == 0:
              print("You lose:(")
              print("The word was ", word)
        
< Previous