mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-02-07 09:00:58 +00:00
Add files via upload
This commit is contained in:
parent
2d95dcb8a3
commit
8671bd125f
2
scripts/Word Guessing Game/requirements.txt
Normal file
2
scripts/Word Guessing Game/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Install random-word module with the command:
|
||||
pip install random-word pyyaml
|
63
scripts/Word Guessing Game/wordguess.py
Normal file
63
scripts/Word Guessing Game/wordguess.py
Normal file
|
@ -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()
|
Loading…
Reference in New Issue
Block a user