Last active
April 18, 2020 23:01
-
-
Save a4vg/de8b280a6e0d738a274a99cdda16462b to your computer and use it in GitHub Desktop.
Simple 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 | |
words = ["apple", "bun", "disgusting", "reflect", "whisper", "dinosaurs", "unknown", "knowledgeable", "energetic"] | |
max_errors = 5 | |
word = random.choice(words) | |
cur_word = ["_"]*len(word) | |
errors = 0 | |
attempts = 0 | |
while "_" in cur_word: | |
print("*"*50) | |
if max_errors==errors: | |
print("You lost, sorry") | |
exit() | |
attempts +=1 | |
for i in cur_word: | |
print(i, end=" ") | |
print() | |
print(word) | |
let_selected = input("Enter letter: ") | |
hit = False | |
for i_letter in range(len(word)): | |
if word[i_letter]==let_selected: | |
cur_word[i_letter] = let_selected | |
hit = True | |
if not hit: | |
errors+=1 | |
print("Oh noo! This word doesn't have a '{}'!".format(let_selected)) | |
print("{} errors left".format(max_errors-errors)) | |
print() | |
print("Word:", word) | |
print("You won in {} attempts with {} errors".format(attempts, errors)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment