Python Forum
Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me)
#2
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:
    # 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.
Reply


Messages In This Thread
RE: Any pointers on my programm before I hand it in?(I'm new to python, so go easy on me) - by deanhystad - Jul-07-2020, 04:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to improve a programm Richard_SS 4 2,871 Mar-17-2019, 04:16 AM
Last Post: Richard_SS
  Help on Creating Program to find the Median and Mode by hand EvanCahill 3 2,992 Jul-19-2018, 06:17 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020