Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import hangman_words
- import hangman_art
- from replit import clear
- stages = ['''
- +---+
- | |
- O |
- /|\ |
- / \ |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- / |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /|\ |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- /| |
- |
- |
- =========''', '''
- +---+
- | |
- O |
- | |
- |
- |
- =========
- ''', '''
- +---+
- | |
- O |
- |
- |
- |
- =========
- ''', '''
- +---+
- | |
- |
- |
- |
- |
- =========
- ''']
- chosen_word = random.choice(hangman_words.word_list)
- display = []
- for letter in chosen_word:
- display += ("_")
- print (hangman_art.logo + "\n")
- print(display)
- str_display = " ".join(map(str, display))
- def again():
- for each in range(len(chosen_word)):
- if chosen_word[each] == guess:
- display[each] = guess
- # def mistake():
- # while guess not in chosen_word:
- # lives = lives - 1
- # if global lives == 0:
- # print ("Game over!")
- # else:
- # print (f"You have {lives} lives left")
- lives = 7
- used_letters = ""
- while "_" in display and lives > 0:
- guess = input("Guess a letter: \n").lower()
- again()
- clear()
- if guess not in chosen_word:
- lives = lives - 1
- print (f"Letter {guess.upper()} is not a part of the word")
- if lives > 0:
- print (f"You have {lives} lives left")
- print (stages[lives])
- print (display)
- used_letters += guess
- print (f"Letter you already used : {used_letters.upper()}\n")
- if lives == 0:
- print ("You Loose!\n" + stages[lives] + "The word was " + chosen_word.upper())
- if "_" not in display:
- print ("You Win!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement