From 8671bd125f65d2a73fb250d412a76885cba65752 Mon Sep 17 00:00:00 2001 From: Shraggus <94532831+Shraggus@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:22:26 +0530 Subject: [PATCH] Add files via upload --- scripts/Word Guessing Game/requirements.txt | 2 + scripts/Word Guessing Game/wordguess.py | 63 +++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 scripts/Word Guessing Game/requirements.txt create mode 100644 scripts/Word Guessing Game/wordguess.py diff --git a/scripts/Word Guessing Game/requirements.txt b/scripts/Word Guessing Game/requirements.txt new file mode 100644 index 0000000..a561d49 --- /dev/null +++ b/scripts/Word Guessing Game/requirements.txt @@ -0,0 +1,2 @@ +Install random-word module with the command: +pip install random-word pyyaml \ No newline at end of file diff --git a/scripts/Word Guessing Game/wordguess.py b/scripts/Word Guessing Game/wordguess.py new file mode 100644 index 0000000..c5245b5 --- /dev/null +++ b/scripts/Word Guessing Game/wordguess.py @@ -0,0 +1,63 @@ +import time +from random_word import RandomWords +r = RandomWords() +print("Welcome") + +def main(): + global count + global display + global word + global finalword + global progress + global length + global playgame + word = r.get_random_word() + finalword = word + length = len(word) + count = 0 + display = '_' * length + progress = [] + playgame = "" + +def replay(): + play = input("Play again? [y/n]: ") + if(play not in ["Y", "y", "N", "n"]): + replay() + if(play == "y" or play == "Y"): + main() + execute() + elif(play == "n" or play == "N"): + exit() + +def execute(): + global count + global display + global word + global progress + global playgame + lives = 10 + guess = input("Enter your guess: ") + if guess in word: + progress.extend([guess]) + index = word.find(guess) + word = word[:index] + "_" + word[index + 1:] + display = display[:index] + guess + display[index + 1:] + print(display + "\n") + elif guess in progress: + print("Already guessed, guess again") + else: + count += 1 + print("Wrong guess. " + str(lives-count) + " lives remaining") + if(count == lives): + time.sleep(1) + print("You Die :(") + print("Word: " + finalword) + replay() + if(word == '_' * length) : + print("You Live! :)") + replay() + elif(count != lives): + execute() + +main() +execute() \ No newline at end of file