Back to Projects
Word Game
“Run” to see new changes
✕
Look inside
Run
main.py
index.html
style.css
Run
import random # Initialize loop variables attempts = 5 word_guessed = False # Introduce the game to the player print("Welcome to the 5-Letter Word Guessing Game!") print("Try to guess the secret 5-letter word.") # List of 5-letter words words = ['apple', 'beach', 'charm', 'dusty', 'eager', 'faith', 'grain', 'happy', 'jolly', 'kitty'] # Select a random word from the list secret_word = random.choice(words) # Loop for 5 guesses while attempts > 0 and not word_guessed: # Ask the player to enter a guess guess = input("\nEnter your guess (5 letters): ").lower() # Check if the guess is not 5 letters if len(guess) != 5: print("Please enter exactly 5 letters.") else: # Check each letter in the guess updated_word = "" for i in range(5): if guess[i] == secret_word[i]: updated_word += guess[i] # Correct letter placed else: updated_word += "-" # Incorrect letter # Display the current progress print("Current progress:", updated_word) # Check if the guess is correct attempts -= 1 if updated_word == secret_word: print("Congratulations! You guessed the word:", secret_word) word_guessed = True if attempts == 0: # Inform the player if they've used all their guesses print("Sorry, you've run out of guesses.") print("The secret word was:", secret_word)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <title></title> <script src="https://cdn.jsdelivr.net/npm/brython@3/brython.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.js"></script> <script type="text/python" src="main.py"></script> </head> <body> </body> </html>
body { font-family: Arial; }
Console
AI Tutor
Documentation
Ask AI Tutor
Click RUN to execute project