i want the bot to Look if "Hello", "hello" or "Hi" is in the input content. I already tried with
hello = ["Hello", "hello", "Hi"]
msg = input()
if hello in msg:
and
hello = ["Hello", "hello", "Hi"]
msg = input()
if hello in str(msg):
If you want to check multiple values, use a list and any()
look_for = ["Hello", "hello", "Hi"]
txt = input(">> ")
if any(x in txt for x in look_for):
print('found')
else:
print('nope')
strings do not contain lists, so list in str will fail
Please try this:
hello=["x", "y", "z"]
msg = input(">> ")
for h in hello:
if h in msg:
print(msg)
else:
print("not in msg")
Requirements
I use this basic code to check for keywords in data sets. its an easy way to test to see if I can find the data im looking for in files.
Try This :
import re
hello = ["Hello", "hello", "Hi"]
msg = "Hi; this is my world"
for i in hello:
if i in msg:
#your condition
else:
continue # else statement will run 3 times since hello has three elements
i in msg will work fine for checking substrings
if 'hello' in msg:Without quotes, it is consideringhelloas a variable and trying to fetch its value. If it is not defined then python crashes