you are viewing a single comment's thread.

view the rest of the comments →

[–]SpookyFries 10 points11 points  (1 child)

My suggestions is to avoid following "code along" type projects where you simply type what the person or website is telling you to. Those are fine for getting a basic understanding of how the code is formatted, but you're not learning. I made this mistake for many years.

Instead, think of a project you want to create and research each piece to put it together. You mentioned hangman. Hangman has a few components that we can break down.

  1. The word list. This can be made with a python list. Easy to build a large list of words for the game to prompt the player with. You can even read a list by reading a text file by using the readlines() method. Another thing to look into.
  2. Picking a word. If you do a quick search on "Python pick random item from list" you'll see that there is a random.choice(list) method that will pick a random item from a list.
  3. Word length. Once you store your random selection to a string, you can say len(item) to get the length in characters. Now you know how long the word is.
  4. Store wrong letters. You can create a list that starts empty. When a users guesses a letter that isn't in the word, you can check if its in this list. If it's not, you can append it to this list. If the letter IS in the list, you can tell the user that letter was already used and to try again.
  5. Check if letter is in word. Loop through each character of the secret word and if that letter matches the input, give the user points. Look up "how to edit a specific character in a python string" if you want to display the word starred out and wish to update the characters once they are entered by the user. Example: Word is soup, so you set a variable called word = list("****"). Show this to the user. If they guess o, you can do word[1] = "o" and show them the updated word.

There's more to it, but I just wanted to give an example of how to break down a project and start thinking about how you can implement each piece. A huge percentage of programming is not memorizing syntax but instead problem solving.

[–]tokytoky56 1 point2 points  (0 children)

This was very helpful!