is user input a letter in the CPU's choice?

I’m trying to check if user input is one of the letters in the chosen word by the CPU. Let me know if this is not possible the way I’m trying to do it, thanks.

import random
test_list = [ 'yes', 'no']
# guessing list
print("Original list is : " + str(test_list))

cpu_choice =[]
cpu_choice=("Random element is :", random.sample(test_list, 1)) 
# i know it gives the answer i'm just using this to test and get the program to work 
userinput = input('guess a letter ')
for letter in userinput:
    if letter in userinput == letter in cpu_choice:
    elif print:

>Solution :

I modified it to loop through the cpu_choice instead of the userinput (userinput is just one letter).

The printing of the result is moved out of the loop so the program won’t print ‘wrong’ for every letter in the word that doesn’t match.

userinput = input('guess a letter: ')[0]
match = False
for letter in cpu_choice[1][0]:
  if letter == userinput:
    match = True
if match:

Leave a Reply