Skip to content

Commit

Permalink
Create main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
souvikpramanikgit authored Oct 28, 2024
1 parent d9c978f commit 5d18321
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Game_Development/Word Games with lives/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import random
lives = 3

words = ['pizza', 'fairy', 'teeth', 'shirt', 'otter', 'plane']
secret_word = random.choice(words)

clue = list('?????')
heart_symbol = u'\u2764'

guessed_word_correctly = False

def update_clue(guessed_letter, secret_word, clue):
index = 0
while index < len(secret_word):
if guessed_letter == secret_word[index]:
clue[index] = guessed_letter
index = index + 1

while lives > 0:
print(clue)
print('Lives left: ' + heart_symbol * lives)
guess = input('Guess a letter or the whole word: ')

if guess == secret_word:
guessed_word_correctly = True
break

if guess in secret_word:
update_clue(guess, secret_word, clue)
else:
print('Incorrect. You lose a life')
lives = lives - 1

if guessed_word_correctly:
print('You won! The secret word was ' + secret_word)
else:
print('You lost! The secret word was ' + secret_word)

0 comments on commit 5d18321

Please sign in to comment.