Simply use `in` operator to check whether <greetings_> contains
if user_input in greetings_:
# code here ...
ice , the reason why the initial code does not give any output, is the not suitable use of *any()* builtin method. in this case it returns *True* since there is at least one valid member in the list *greetings_*. > we are comparing (e.g. input is 'hi'): user_input == any(greetings_) -> 'hi' == True -> False if there would be an *else* clause defined, this would be executed. here is a small code to demonstrate how any() can be used: https://code.sololearn.com/cjkqjShN5gLq/?ref=app
if user_input in greetings_: print(random.choice(response_))
if any([user_input == word for word in greetings_]): print(random.choice(response_))
Let me help. Your code: import random user_input = input() greetings_ = ["hi", "hey", "hello",] response_ = ["howdy", "wassup", "hello"] if user_input == any(greetings_): print(random.choice(response_)) The reason why it didn't output any thing is because the user input did no match anything thing return by the any() function. any() would return : True or False, if and item in the iterable is not empty, eg : any([1,0,3]) == True because one of the items is > 0, any([0,0,0]) == False because all the items are ==0 or empty, The same applies to empty strings and non-empty string. The best way is to correct your code in the if condition check it: https://code.sololearn.com/cNWbgF5v6gtn/?ref=app
Use != Operater Instead of == u will get ur output
Use != Operater not == 🤩
Please help me with HTML
What is the mistake here?
Unable to overload +
I have tried every way I could find but still I can't display my local images ..what am I doing wrong?
Pls rectify the errors.
Python list half printed