Use the in keyword to test if an array contains a value.
def compare(typeOfColors):
introduceC = input("Introduce a color")
while introduceC.lower() not in typeOfColors:
print("Error")
colors = ["white", "black"]
compare(colors)
But that introduces a new error, infinite looping, which you could solve like this:
def compare(typeOfColors):
introduceC = input("Introduce a color: ")
if introduceC.lower() not in typeOfColors:
print("Error")
return compare(typeOfColors)
print('Exists!')
return introduceC
colors = ["white", "black"]
compare(colors)
Giving:
Introduce a color: red
Error
Introduce a color: blue
Error
Introduce a color: whitE
Exists!
If the user inputs something that is not in the accepted values, the function calls itself, effectively restarting. That is recursion.
forstatement? docs.python.org/3/tutorial/controlflow.html#for-statementsintroduceC.lower() in typeOfColorsis enough to know if the lower version of the input string is present in the list