I know this post here : Testing user input against a list in python
but, being new (here and at programming) I was not sure if bumping a 3 years old post was ok or if I needed to make a new one. I apologize for that.
I checked the documentation also but I did not understand fully after reading, why this code would NOT print the line "not in selection" after running it.
I would like to make it so that the user input is tested against the list "selection". (assuming the user enters only low caps between a to z)
I tried inputs like 'a' or 'test' but "not in selection" still prints out, as if it didn't recognize the input.
Could someone help me with this one ? I am trying to make a hangman game :)
selection = list('abcdefghijklmnopqrstuvwxyz')
gameword = []
user_input = input('input a gameword> ')
gameword = list(user_input)
if gameword not in selection:
print('not in selection')
Edit++
I realized that I need all of those: "islower, isalpha, isdigit
problem is, I cant seem to combine all that and still make it work. or come up with a more appropriated way to do this.
this is what I ended up with before I realize I needed to combine them all:
while True: # loop to get the user input
user_input = input('input> ') # store input in 'user_input'
gameword = list(user_input) # list inside gameword
if user_input == 'q': # loop ends when q is entered
break # break statement
if len(user_input) <= 4 or len(user_input) >= 9: # checks the length of the string input
print('5 to 8 letters ') # prints the restriction on screen
for i in gameword: #
if i.islower() not in selection # checks if lowercase are used
print('only low letters please') # prints the restriction on screen
for i in gameword: #
if i.isalpha() not in selection: # check if is alphabet letter are used
print('only letters') # prints the restriction onscreen
for i in gameword: #
if i.isdigit() in selection: # checks if digits are in word list
print('no numbers plz') #
`
but it keeps printing the lines "only low letters please" instead of just check conditions and then print "wrong input message" then tries to get the input again before the game starts...
I would love more advice about this :)