Skip to content

Instantly share code, notes, and snippets.

import time,os
stickmen = [
"\
|------\n\
| O\n\
| ---|---\n\
| / \\ \n\
| / \\ \n\
|_____",
import os
#Global variables and lists to be used throughout my program.
wordsList = ["dog","cat","mouse","hyena"]
usedWords = []
lives = 6
stickmen = [
"\
def getALetter():
global lives
global usedLetters
letter = input("please enter a letter")
if not len(letter) == 1: #Have they entered only 1 character?
mainScreen()
elif not letter.isalpha(): #Is that character a letter?
mainScreen()
elif in usedLetters: # Have they already guessed that letter?
import os,random
#Global variables and lists to be used throughout my program.
wordsList = ["dog","cat","mouse","hyena"]
usedLetters = []
chosenWord = random.choice(wordsList)
lives = 6
stickmen = [
def showUsedLetters():
print(" ".join(usedLetters)) #Join up the letters in the usedLetters list
#into one long string and print it! Easy :-)
def drawTheWord():
word = [] #Create a temporary list to add either letters or an underscore
for letter in chosenWord:
if letter in usedLetters:
word.append(letter)
else:
word.append("_")
print(" ".join(word)) #Combine the letters and underscores and print them out.
# The string.join(list) method is easy to use and powerful! :-)
def checkWinLose():
global lives #These variables need to global so that they save outside of the function
global chosenWord
global usedLetters
if lives == 0: #If you have no lives the you have lost!
os.system('clear')
print("\n\nYou lose!!!!!")
input("\n\nPress enter to start again")
chosenWord = random.choice(wordsList)#After here reset lives,empty usedLetters and pick a new word.
lives = 6
def mainScreen():
checkWinLose() # Add me to the mainScreen function!
#rest of function here....
@richardbwest
richardbwest / hangmanexample.txt
Last active July 23, 2016 22:18
A basic example of just a stickman for use in our hangman game.
stickman = "\
|------\n\
| O\n\
| ---|---\n\
| / \\ \n\
| / \\ \n\
|_____"
print(stickman)
def drawStickMan():
print(stickmen[lives])