dimanche 3 février 2019

check if any character of a string is inside a list

This is a Pig latin game and it works but right now if I input any of the characters defined by the variable "special" I get it returned as True but if I add another character it returns as false.


So it's only checking if the whole string and not any character of the string. I want that if I input "Ban/", it gets returned as invalid. So if any of the characters defined in "special" are found in "word" I want it to return true.

special = list('[@_!#$%^&*()<>?/\|}{~:]')
word=input("\nType in a word : ")
if word in special:
    print("Your entry is not valid.")
else:
    pigLatin()

i also tried this before but it's essentially the same

if word[0:] in special:

Here's the full snipet if it helps. Condition is in Line:41

Beware I started a few days ago so it may look really messy.

Aucun commentaire:

Enregistrer un commentaire