Skip to content

Commit

Permalink
Move output into draw_output() function
Browse files Browse the repository at this point in the history
  • Loading branch information
pamims committed May 28, 2022
1 parent ab5a617 commit 6a02989
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Day007/Hangman/hangman.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import random;

def draw_output(correct_letters, incorrect_letters):
print(f"The word so far: {correct_letters}");
print(f"Incorrect guesses: {incorrect_letters}");
return;

ALLOWED_FAILURES = 6;
words = ["buffalo", "parrot", "squirrel", "hedgehog"];
word = random.choice(words);
Expand All @@ -8,6 +14,7 @@

letters_remaining = len(word);
while letters_remaining > 0 and len(incorrect_letters) < ALLOWED_FAILURES:
draw_output(correct_letters, incorrect_letters);
guess = input("Guess a letter: ").lower();
if guess in correct_letters or guess in incorrect_letters:
print("That letter has already been used.");
Expand All @@ -28,9 +35,6 @@
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!");
Expand Down

0 comments on commit 6a02989

Please sign in to comment.