Jul-10-2020, 12:44 PM
Hi everyone,
I hope you're all keeping safe during this time.
I'm trying to create a word game in Python (using Thonny), whereby the user has to come up with a word from a random sample of ten letters.
I have managed to get the code to match whereby, if letters not in the sample, are used, the user is reminded to use the ones in the sample.
But I'm finding that my "print" command is printing for each character used in the word, as opposed to just the word itself. It is also increasing the score three times instead of once.
Please see image below for reference.
If you can help me, I would be very grateful.
Kind regards,
paulmerton4pope
I hope you're all keeping safe during this time.
I'm trying to create a word game in Python (using Thonny), whereby the user has to come up with a word from a random sample of ten letters.
I have managed to get the code to match whereby, if letters not in the sample, are used, the user is reminded to use the ones in the sample.
But I'm finding that my "print" command is printing for each character used in the word, as opposed to just the word itself. It is also increasing the score three times instead of once.
Please see image below for reference.
import random parhau = True letters = [] for num in range (97,123): letters.append (chr(num)) x = 0 rlist = random.sample(letters,10) print (rlist) while parhau: word = str(input ("Please enter a word ")) for ch in str(word): if not ch in rlist [1:11]: print ("Nay - try again!") if ch in rlist and len (word) >= 3: x += 1 print ("Boom! Your score is now " + str(x + 1) )I am a complete beginner with Python, so please do bear with me.
If you can help me, I would be very grateful.
Kind regards,
paulmerton4pope