Here’s a basic Word Scramble game in Python:
import random
def get_random_word():
words = ['python', 'java', 'swift', 'javascript', 'hangman']
return random.choice(words)
def scramble_word(word):
word_letters = list(word)
random.shuffle(word_letters)
return ''.join(word_letters)
def play_game():
word = get_random_word()
scrambled = scramble_word(word)
print("Welcome to Word Scramble!")
print(f"Scrambled word: {scrambled}")
attempts = 3
while attempts > 0:
guess = input("Guess the word: ").strip().lower()
if guess == word:
print("Congratulations! You guessed it right.")
return
else:
attempts -= 1
print(f"Wrong guess! Attempts left: {attempts}")
print(f"Out of attempts! The correct word was '{word}'.")
play_game()
How it Works
- A random word is chosen from a list and scrambled.
- The player has 3 attempts to guess the word.
- If guessed correctly, they win; otherwise, they lose.
You can expand the game by adding more words, levels, or hints!
Leave a Comment