0% found this document useful (0 votes)
9 views2 pages

Samplegame Py

Uploaded by

jimmyowen390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Samplegame Py

Uploaded by

jimmyowen390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

START

Initialize game settings


Load word list
SELECT a random word from the list
CONVERT selected word into clues or puzzles
DISPLAY game instructions and current puzzle state

WHILE player has chances AND word is not fully guessed


PROMPT player for a letter guess
IF guess is correct
UPDATE puzzle state to reveal guessed letters
DISPLAY updated puzzle state
ELSE
DECREMENT player's remaining chances
DISPLAY updated chances and current puzzle state
ENDIF
ENDWHILE

IF word is fully guessed


DISPLAY victory message
ELSE
DISPLAY game over message and reveal the word
ENDIF
END
import random

# List of words and clues


words = {
"python": "A type of snake and also a programming language.",
"galaxy": "A massive, gravitationally bound system of stars, stellar remnants,
interstellar gas, dust, and dark matter.",
"ocean": "A vast body of salt water that covers almost three quarters of the
earth's surface."
}

# Select a random word and its clue


word, clue = random.choice(list(words.items()))
guessed = ["_" for _ in word] # Track guessed letters
attempts = len(word) + 3 # Number of allowed attempts

print("Welcome to the Guess the Word Game!")


print("Clue:", clue)
print("Guess the word: ", " ".join(guessed))

while attempts > 0 and "_" in guessed:


guess = input("Enter a letter: ").lower()
if guess in word:
for index, letter in enumerate(word):
if letter == guess:
guessed[index] = guess
print("Correct! ", " ".join(guessed))
else:
attempts -= 1
print("Wrong! Attempts left:", attempts)

if "_" not in guessed:


print("Congratulations! You've guessed the word:", word)
break
elif attempts == 0:
print("Game Over! The word was:", word)

You might also like