lundi 21 novembre 2022

trying to guess letter in the randomly choosen cpu word from wordbank and return it

im trying to guess letter in the word and return it with "if letter in cpu_choice:" the desired output is you guess a letter thats in the cpus word and it will return if your guess is in the cpus word or not. sort of like hangman

 import random
test_list = ["apple", "bat","cow", "dog", "eat"]

print("Original list is : " + str(test_list))

cpu_choice=("Random letter is :", random.sample(test_list, 1))
print (cpu_choice)





userinput = input('chose a letter :')
for letter in userinput:
    if letter in cpu_choice:
            print("correct",cpu_choice.upper())
    else: 
            print ("incorrect",userinput) 
                

>> cpu_choice = apple 
>> userchoice = p 
>>print correct 


>> cpu_choice = apple 
>> userchoice = c 
>> print incorrect 



Aucun commentaire:

Enregistrer un commentaire