4
\$\begingroup\$

I created this hangman game today as my first stand alone project. It is a quite basic and simplified approach. How could I improve the game to make it more interesting?

 import random
 words = ["abductions", "abridgment", "admixtures"
 ,"backfields", "blueprints", "chivalrous", "complexity", "cyberpunks", "desolating", 
 "duplicator","earthlings", 
 "fluoridate","flustering","fornicates","godfathers","humanizers","ideographs","journalism",
 "languished","logarithms","mendacious","neighborly","outlandish","palindrome","philanders"
 ,"proclaimed","randomizes","shrinkable","sublimated",
 "truckloads","upholstery","vanquished","vulcanizes","wanderlust","womanizers" ]
 i = random.randint(0, len(words) - 1)
 word = words[i]
 guesses = "_"*len(word)
 print(guesses)
 lives = 0
 while lives < 5:
 character_check = input("")
 if character_check in word and character_check != word:
 a = word.index(character_check)
 guesses = guesses[:a] + word[a] + guesses[a+1:]
 print(guesses)
 if guesses == word or character_check == word:
 print("Winner!")
 break
 elif character_check not in word:
 print(lives)
 lives += 1
 if lives == 5:
 print("You lose! It was {}".format(word))
Zoran Jankov
7592 gold badges7 silver badges26 bronze badges
asked Nov 18, 2020 at 13:48
\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

This is a great start. Let me point out a few things you should consider.

Make it interactive

When I ran the code, it produces some numbers whenever I lose a guess, it took a while to figure out that it was my guess count incrementing. A nice prompt message would be helpful. Also the guess count should reduce for each guess made.

Avoid hardcorded values

What is 5 in the following statement while lives < 5:. it can be written as follow

MAX_LIVES = 5
while lives <= MAX_LIVES:

Misleading names

character_check is just too misleading, promises one thing(to check a character) and does another thing(recieves input from the user). This can rewritten as user_input

Features worth adding

  1. You could make the game a class,implement a board class to nicely draw the man being hung.
  2. You could also implement a hint package interface, user might want to buy and use hints when they are stuck.
answered Nov 19, 2020 at 13:51
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks! I have since changed a couple things already. I did notice afterwards that the lives should have been decreasing not increasing, I had like a D'oh moment. I like the idea for hints, I'll try to incorporate that. \$\endgroup\$ Commented Nov 19, 2020 at 19:13
1
\$\begingroup\$

A couple of coding suggestions...

  1. You can use random.choice(words) to pick a random item out of the words list.

  2. I'd be tempted to sys.exit() instead of break on winning. That way you don't need to test the value of lives - if you reach the end of the while loop you have lost.

In terms of making the program 'more interesting', I'd add a welcome message, maybe explain the rules. Maybe also display a list of letters already guessed and do nothing if the same letter is guessed twice? (Right now choosing the same letter 5times loses the game). you could also have short, medium and long (or easy, medium, hard) word lists and ask the person to choose which they want to use.

answered Nov 18, 2020 at 14:11
\$\endgroup\$
1
  • \$\begingroup\$ Thanks! I'll try to implement those things as soon as possible \$\endgroup\$ Commented Nov 19, 2020 at 11:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.