LETTERS = "abc"
correct = "cab "
guess = ""
while guess != correct:
for i in LETTERS:
position = random.randrange(len(LETTERS))
guess += LETTERS[position]
LETTERS = LETTERS[:position] + LETTERS[(position + 1):]
print(guess)
I'm new in Python and I want to make this simple program:
- With the letters "abc", jumble them and create a new three-lettter word randomly.
- Print that jumble
- Continue doing this loop until the computer jumbles "cab".
- Then stop.
I came up with this code, and it gives me an infinite loop. I can't figure out why is doing it. I'm sure it's something easy but I can't see it. Need some help! Thanks!
correctvalue with a space?LETTERSon every iteration of the for-loop. Needs to alter a copy of LETTERS instead with amyLetters = LETTERS[:]immediately inside the while-loop (and resetguesstoo)