Best4Hack

Best4Hack is the site where you can learn Ethical Hacking and Cracking get latest Tips and Tricks free Hacked and Cracked Software get SEO.

Best4Hack

Best4Hack is the site where you can learn Ethical Hacking and Cracking get latest Tips and Tricks free Hacked and Cracked Software get SEO.

Best4Hack

Best4Hack is the site where you can learn Ethical Hacking and Cracking get latest Tips and Tricks free Hacked and Cracked Software get SEO.

Best4Hack

Best4Hack is the site where you can learn Ethical Hacking and Cracking get latest Tips and Tricks free Hacked and Cracked Software get SEO.

Best4Hack

Best4Hack is the site where you can learn Ethical Hacking and Cracking get latest Tips and Tricks free Hacked and Cracked Software get SEO.

Showing posts with label Python Codes. Show all posts
Showing posts with label Python Codes. Show all posts

Saturday, 22 December 2012

Hangman Game in python


# The classic game of Hangman. The computer picks a random word
# and the player tries to guess it, one letter at a time. If the player
# can't guess the word in time, the little stick figure gets hanged.
#
# Nakamura Michiko
#https://www.facebook.com/id.23764596423?ref=tn_tnmn
#Note you cant play without install python
#
# import random

import random
# constants

HANGMAN = (
"""
----
| |
|
|
|
|
|
|
|
----------
""",
"""
----
| |
| O
|
|
|
|
|
|
----------
""",
"""
----
| |
| O
|-+-
|
|
|
|
|
|
----------
""",
"""
----
| |
| O
|/-+-
|
|
|
|
|
----------
""",
"""
----
| |
| O
|/-+-/
|
|
|
|
|
----------
""",
"""
----
| |
| O
|/-+/
| |
|
|
|
|
----------
""",
"""
----
| |
| O
|/-+/
| |
| |
||
||
|
----------
""",
"""
----
| |
| O
|/-+/
| |
| |
|| |
|| |
|
----------
""")
MAX_WRONG = len(HANGMAN) - 1
WORDS = ("KANYE","HATERS", "KEEP", "HATING","STILL","FUCKING","KIM")
# initialize variables
word = random.choice(WORDS)
# the word to be guessed
so_far = "-" * len(word)
# one dash for each letter in word to be guessed
#number of wrong guesses
wrong = 0
#letters already guessed
used = []
print "\t\tWelcome to Hangman. Good luck!"
while (wrong < MAX_WRONG) and (so_far != word):
    print HANGMAN[wrong]
    print "\nYou've used the following letters:\n", used
    print "\nSo far, the word is:\n", so_far
    guess = raw_input("\n\nEnter your guess: ")
    guess = guess.upper()
    while (guess in used):
        print "You've already guessed the letter:", guess
        guess = raw_input("Enter your guess: ")
        guess = guess.upper()
    used.append(guess)
    if (guess in word):
        print "\nYes!", guess, "is in the word!"
    # create a new so_far to include guess
        new = ""
        for i in range(len(word)):
            if guess == word[i]:
                new += guess
            else:
                new += so_far[i]
        so_far = new
    else:
        print "\nSorry,", guess, "isn't in the word."
        wrong += 1
if (wrong == MAX_WRONG):
    print HANGMAN[wrong]
    print "\nYou've been hanged!"
else:
    print "\nYou guessed it!"
print "\nThe word was", word
raw_input("\n\nPress the enter key to exit.")

Related Posts Plugin for WordPress, Blogger...