Jul-07-2020, 04:12 AM
Your replay logic does not work. You can only play the game once. If I try to play again the game says "You have guessed the word!" each time I enter a letter. It is also odd that the replay logic is inside the function that manages the game.
The random_word function is a neat idea, but poorly executed. Randdom_word should return a random word. In the future you might change this game to pull words out of a file or a database or some other means. The actual mechanism should be invisible to the rest of your game. But your implementation of random_word is full of game details. Random_word should not have to know about guessed_letters and wrong_guesses and list_space1. Those are game details, not getting the random word details.
You overuse "global". Global variables should be uses sparingly. In a small program like this it does not cause many problems, but if you had a large program with many global variables it would be difficult to keep track of where variables are used and where they are modified. There is no reason for you to use any global variables in your game at all.
Your comments could be better. What does this program do? I ran it and it plays hangman. Why isn't there a docstring right at the top of the file saying "This program plays hangman"? Why isn't there a docstring describing the purpose and use of each function?
Your comments are also too long. Write your code using code, not comments. If it isn't clear what the code does, reorganize the code so the purpose is clear. This comment:
Overall, not bad. Lots of room for improvement, but better than the first program I wrote.
The random_word function is a neat idea, but poorly executed. Randdom_word should return a random word. In the future you might change this game to pull words out of a file or a database or some other means. The actual mechanism should be invisible to the rest of your game. But your implementation of random_word is full of game details. Random_word should not have to know about guessed_letters and wrong_guesses and list_space1. Those are game details, not getting the random word details.
You overuse "global". Global variables should be uses sparingly. In a small program like this it does not cause many problems, but if you had a large program with many global variables it would be difficult to keep track of where variables are used and where they are modified. There is no reason for you to use any global variables in your game at all.
Your comments could be better. What does this program do? I ran it and it plays hangman. Why isn't there a docstring right at the top of the file saying "This program plays hangman"? Why isn't there a docstring describing the purpose and use of each function?
Your comments are also too long. Write your code using code, not comments. If it isn't clear what the code does, reorganize the code so the purpose is clear. This comment:
# check if answer in word # loop through all the numbers in range(len(word)) # if word len = 4 then loop through range(4) # if answer == word[i] # list_space[i] = answer\ # when loop again it checks if you guessed the letter # if so print etc. This shouldnt change the for loop.Should be more like this comment:
Update display to show correctly guessed letters. Game is over when all letters are guessed.I think the wrong_guesses list is a great idea, but the implementation is not quite right. Instead of checking against previous guesses and saying "You already guessed that", why not display the guessed letters? Something like this:
Output:Word: __e_d Guessed Letters: cedgm
Why is there a 1 second delay when I quit the game? I thought something had broken. Why are you using sys.exit()? Can you think of a more elegant way to exit the program?Overall, not bad. Lots of room for improvement, but better than the first program I wrote.