Well say gameword
was hello
. Now if the program searches for the list ['h', 'e', 'l', 'l', 'o']
in abcdefghijklmnopqrstuvwxyz
, it isn't going to find it, because the entire word isn't present as a whole. You might want to change your code as such:
selection = list('abcdefghijklmnopqrstuvwxyz')
gameword = []
user_input = input('input a gameword> ')
gameword = list(user_input)
for k in gameword:
if k.lower() not in selection:
print('not in selection')
You are checking if the entire list is in the selection, which it isn't. A fix for this is using a for
loop to loop over each individual character in selection
, not every character at once.
EDIT: Here is the second set of code, answering your second question:
selection = list('abcdefghijklmnopqrstuvwxyz')
gameword = []
user_input = input('input a gameword> ')
user_input = str(user_input)
gameword = list(user_input)
for k in gameword:
if k.isdigit() == True:
print('no digits please')
break
if k.isalpha() == False:
print('only alphabets please')
break
if k.islower() == False:
print('only lowercase please')
break
if k not in selection:
print('not in selection')
break
I hope I understood what you were asking correctly :D