Skip to content

Instantly share code, notes, and snippets.

@loren138
Last active July 13, 2017 19:39
Show Gist options
  • Save loren138/252872c60e076f0c35ba3f7df27e5ca5 to your computer and use it in GitHub Desktop.
Save loren138/252872c60e076f0c35ba3f7df27e5ca5 to your computer and use it in GitHub Desktop.
Hangman Psuedocode
from __future__ import print_function
import numpy
# Save this file using file save in your browser
# Do not copy paste into PyCharm as it will mess up the indentation
# and thus your code will not run properly.
# Print Hangman's current state
def printHangman(numberWrong):
# Print the hangman
# TODO print top of noose
if numberWrong >= 1:
# TODO print head
else:
# TODO don't print head
if numberWrong >= 2:
# TODO print neck
else:
# TODO don't print neck
if numberWrong >= 3:
# TODO print arms # Backslash is a spacial character so using two creates one
else:
# TODO don't print arms
if numberWrong >= 4:
# TODO print body
else:
# TODO don't print body
if numberWrong == 5: # can't be > here so we get to the else :)
# TODO print left leg
elif numberWrong >= 6:
# TODO print both legs
else:
# TODO don't print any legs
# TODO print bottom of noose
def printBlanks(word, correctLetters):
# TODO Set solved equal to true (innocent until proven guilty)
# TODO Loop over each letter in the word for l in word:
l = l.lower() # not required but nice to have
# Check if that letter is in the list of correct letters
if False: # TODO Remove "False" and replace it with the appropriate condition
# TODO If it is, print the letter and a space
else:
# TODO If it isn't, print an underscore and a space
# TODO Also, set solved equal to False
print()
print()
return solved
# TODO Define a list of words as options
# TODO Define a list to hold the correctly guessed letters
# TODO Define a variable to count the number of incorrect guesses
# TODO Pick a random word to be used
# TODO Repeat forever, we'll use a break to get out
# TODO Print the Status of the Hangman (Hint: Call your function)
# TODO Print the word blanks and see if they solved it
solved = False # TODO Replace False with a function call
# TODO Catch Death (Exit loop if they got 6 or more wrong)
if solved:
print('You win!')
break # no need to guess again
# TODO Define a variable to hold user input
# TODO Loop until they give a letter
# Check if the letter is in the word
if True: # TODO Replace True with the correct condition
# TODO If it's right, put it in the correct letters list and let them know it was right
else:
# TODO If it's wrong, increment the wrong count and let them know it was wrong
print()
# TODO Reveal what the word was
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment