Created
October 15, 2022 12:17
-
-
Save aiham-lab/d65037bf6cee9870ea0915ef86124126 to your computer and use it in GitHub Desktop.
Hangman Game
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
import random | |
import hangman_words | |
import hangman_art | |
print(hangman_art.logo) #logo | |
# Random choise of words lists | |
chosen_word=random.choice(hangman_words.word_list) | |
# Random choise of words lists | |
# turn the chosen word to a list | |
display=list(chosen_word) | |
for n in range(0,len(display)): | |
display[n]="_" | |
print(display) | |
# turn the chosen word to a list | |
# num of lives | |
lives=6 | |
# num of lives | |
#while loop to start the game | |
while ('_' in display) and (lives>0): | |
# user char input | |
userGuess=input("Choos a letter : ").lower() | |
# user char input | |
# if statment to check if chosen char is from the word | |
if userGuess not in chosen_word: | |
lives-=1 | |
print(f"you have {lives} chance") | |
print(hangman_art.stages[lives]) | |
else: | |
print("correct") | |
count=-1 | |
for i in chosen_word: | |
count+=1 | |
if i == userGuess: | |
print("Right") | |
display[count]=i | |
print(' '.join(display)) | |
print("GAME OVER") | |
if lives==0: | |
print("YOU LOST") | |
else: | |
print("YOU WIN") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment