Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Game
#2
Hello paulmerton4pope,

The reason your print command is printing once for every letter is because it is included in your loop for ch in str(word):. If you remove a couple of indent levels (have your print line at the same level as your for loop above it), it will only print once after your loop is done.

There are a handful of other issues to note:
  1. From a style standpoint, it's preferable not to have spaces between function names and parentheses. print(something) is preferred over print (something}, and so on. You've done this correctly in some lines but not others.
  2. There are simpler ways to create a list of letters than looping through the chr() function as you do in lines 5 and 6. Also, keep in mind that you can iterate through a string just as easily as through a list, so you don't necessarily require a list at all.
  3. The input() function returns a string value by default, so you don't need to use str() in lines 12 and 13, since that value will already be a string.
  4. Your slice in line 14 means that the first letter in the list is not considered valid, since indexes begin at 0 and not at 1. You don't need to include any index values at all since you are considering your whole list, so you could just use rlist instead of rlist[1:11]. (Note that this is another place where it's preferable NOT to include a space.)
  5. You may want to rethink the logic of your scoring system. As it currently stands, a user still gets points for each valid letter, even if they include invalid letters in the word. You might want to start by evaluating whether there are any invalid letters. If so, tell the user and prompt for another word. Only loop through and give points for each letter after you've verified that all of them are valid.
  6. Unless you are meaning to add 1 to the score each time you print it, you should use just x instead of x + 1 on line 18.

Don't let any of these comments discourage you! You are off to a good start with what you've done so far.
Reply


Messages In This Thread
Word Game - by paulmerton4pope - Jul-10-2020, 12:44 PM
RE: Word Game - by GOTO10 - Jul-10-2020, 04:51 PM
RE: Word Game - by menator01 - Jul-10-2020, 04:58 PM
RE: Word Game - by menator01 - Jul-10-2020, 07:10 PM
RE: Word Game - by paulmerton4pope - Jul-11-2020, 02:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 3,025 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,494 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,999 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,830 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,670 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

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