Hangman v2

posted Jan 28, 2016, 7:46 AM by Attila Lengyel   [ updated Jan 28, 2016, 8:00 AM ]
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("")

    
print("This will be my hangman game")

drawHangman(0)
drawHangman(1)
drawHangman(2)
drawHangman(3)
drawHangman(4)
drawHangman(5)
drawHangman(6)

iMissed = 0

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





Comments