-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import random; | ||
ALLOWED_FAILURES = 6; | ||
words = ["buffalo", "parrot", "squirrel", "hedgehog"]; | ||
word = random.choice(words); | ||
|
||
correct_letters = ['_'] * len(word); | ||
incorrect_letters = []; | ||
|
||
letters_remaining = len(word); | ||
while letters_remaining > 0 and len(incorrect_letters) < ALLOWED_FAILURES: | ||
guess = input("Guess a letter: ").lower(); | ||
if guess in correct_letters or guess in incorrect_letters: | ||
print("That letter has already been used."); | ||
continue; | ||
elif not guess.isalpha(): | ||
print("That is not a letter."); | ||
continue; | ||
|
||
i = 0; | ||
is_in_word = False; | ||
for letter in word: | ||
if guess == letter: | ||
is_in_word = True; | ||
correct_letters[i] = letter; | ||
letters_remaining -= 1; | ||
i += 1; | ||
|
||
if not is_in_word: | ||
incorrect_letters.append(guess); | ||
|
||
print(f"The word so far: {correct_letters}"); | ||
print(f"Incorrect guesses: {incorrect_letters}"); | ||
|
||
print("Game Over"); | ||
if len(incorrect_letters) < ALLOWED_FAILURES: | ||
print("Player wins!"); | ||
else: | ||
print("Player loses :("); |