# Happy Anniversary to Me! 🍰

I thought i’d make my anniversary special by posting, so here I go

Cake Day Python Game -

``````""""HANGMAN"""
#HAPPY CAKE DAY TO ME! lol.

hangman = [
"""
-------o""",
"""
^
|
|
|
|
|
-------o""",
"""
-----^
|
|
|
|
|
-------o""",
"""
-----^
|    |
|
|
|
|
-------o""",
"""
-----^
|    |
O    |
|
|
|
-------o""",
"""
-----^
|    |
O    |
|    |
|
|
-------+""",
"""
-----^
|    |
O    |
/|    |
|
|
-------o """,
"""
-----^
|    |
O    |
/|\   |
|
|
-------+""",
"""
-----^
|    |
O    |
/|\   |
/     |
|
-------o""",
"""
-----^
|    |
*_*   |
/|\   |
/ \   |
|
-------o"""]

name = input("\n\nHello there what's your name? ")
print("\nNice to meet you " + name)
ask = input("\nWanna play a 2 player game of Hangman? ")
if ask == 'yes' or ask == 'y':
print("Let's get started then!\n\n")
else:
exit(0)

print("How this works is Player 1 gives Player 2 a word to guess, or vice versa.")

tries = len(hangman) - 1
hz = 0 #size_of_hangman
word = input("\nEnter your hidden word: ")
lenw = len(word)
wrong = 0
for n in range(50): #making sure the user doesn't know the word they are to find
print(" ")
play = True

guessed = " " #letters guessed
correct = ""

print(hangman[hz])
while len(correct) != len(word) and tries != 0:
print('\n Bob: ' + hangman[hz])
print()
for char in word:
if char in guessed:
print(char,)
else:
print("_")
wrong += 1
if wrong == 0:
print()
print("\nYOU WON!\n"*50)
print()
break
print()

#make the user keep guessing
guess = input("Enter a letter you think is in the word: ")
guessed += guess
if guess not in word:
print()
print('Sorry ' + "[" + guess + "]" + ' is not in my word.')
print()
hz+=1
tries -= 1
print("\nYou have " + str(tries) + " turns left.")
else:
if guess in word:
correct += guess
if tries == 0:
print("You Lose.")
if guessed == word:
print("You win!")
exit(0)

if correct != word:
print()
print("\n Sadly your friend has been hanged!")
print('\nHangman: ' + hangman[hz])
else:
print()
print("\nYOU WON!\n"*50)
print()
print("\nThe word was, " + word + "\n")
``````

Run it here: https://repl.it/G9t6/0

Feel free to test it out, and then give me feedback.

3 Likes

Haven’t run it, yet, but please toss it up on Repl.it and post the link so we can run it without any inconvenience would be my suggestion. When we see it work it will be easier to offer constructive criticism. Thanks!

Happy anniversary, btw. Good to see you around.

3 Likes

A little archaic, perhaps?

``````>>> guess = "h"
>>> print("Sorry, [{:s}] is not in my word.".format(guess))
Sorry, [h] is not in my word.
>>>
``````

Edited

``````#simple :)
print "Happy Anniversary Bandit(Super User)"
``````
4 Likes

no prob, posting link rn,

Thanks Roy

Haha old is gold,

but yea I changed it to,

`print("Sorry, [%s] is not in my word." % (guess))`

1 Like

Also, old school. `str.format()` is the new way, and much more powerful once you learn the in’s and out’s. Mind, if you want it to run in this environment, then yes, that is the way to go. We need a polyfill to use `str.format()` in Python 2.

Oh. Well we live, we learn. @mtf picks me out from the cave I’ve been living in. All corrected! Have you checked it out on my repl

Your OP should stay as it was. The Repl.it link should be in new post. This is to maintain some continuity and not make followng posts look stupid. All we need is the link, not the details (a space in front of the URL keeps it from pre-caching).

https://repl.it/G9t6/0

1 Like