Hangman v3

posted Feb 9, 2016, 7:16 AM by Attila Lengyel
def counter(sWord, sChar):
    iCount = 0
    for x in range (0,len(sWord)):
        if sWord[x] == sChar:
            iCount += 1
    return iCount

def drawHangman(missedGuess):
    if missedGuess > 0:
        print("       _________")
    else:
        print("")
    if missedGuess > 1:
        print("       |        |")
    else: 
        print("       |        ")
    if missedGuess > 2:
        print("       |        0")
    else: 
        print("       |        ")
    if missedGuess > 3:
        print("       |       /|\\")    
    else: 
        print("       |        ")
    if missedGuess > 4:
        print("       |        |")
    else: 
        print("       |        ")
        
    if missedGuess > 5:
        print("       |       / \\")
    else: 
        print("       |        ")
    
    print("       _________")
    print("")

def printWord(sWord, sCorrectLetter):
    returnString = ""
    for x in range(0, len(sWord)):
        if counter(sCorrectLetter, sWord[x]) == 0:
            returnString += "*"
        else:
            returnString += sWord[x]
    print(returnString)
    print(len(sWord))

print("This will be my hangman game")

iMissed = 0
sCorrectLetter = ""
sWord = input("Give me a word:")
sGuess = ""
while sGuess != "stop":
    sGuess = input("Guess a letter:")
    
    if counter(sWord, sGuess[0]) == 0:
        iMissed += 1
    else:
        sCorrectLetter += sGuess[0]
    
    drawHangman(iMissed)
    printWord(sWord, sCorrectLetter)

Comments