I wrote the following function in Python, however it does not work. I tried different colors from the paint_colors list and the function only returns found if I give pink as an input. Moreover, for example if I type green as input it returns not found, but this color is also in the paint_colors list.. Why does my function not work for the other colors?
paint_colors = ["pink", "white", "red", "green", "brown", "purple", "blue"]
color_input = input("Enter the color you are looking for:")
def function():
for color in paint_colors:
if color == color_input:
return "found"
else:
return "not found"
print(function())
color_inputas a parameter of your function, not a global variable (even though these solutions "work"). For example:def function(color_input):. That is a more important point than the syntax that the other answers are helping you with.