def chat():
print('start chatbot')
while True:
inp = input("user :")
ifinf == "End":
print ('Exit chatbot service')
break
data = "Hello" or "Hi"
if data:
print("How may I help you?")
else:
print('Will you say that again?')
chat()
When the input value is 'Hello', 'Hello', 'Hi', and 'Hi', "How can I help you?""
When another value comes in, "Can you say that again?"
I want to do it, but I don't know
If you do that, you'll get "What can I do for you" in any input <
Should I use the for statement? Where is the difference?
data = ["Hello", "Hello", "Hi"]
if inp in data:
How may I help you?')
The code you wrote is always 'How can I help you?The reason why it only appears is because the data value in the code below is true which is boolean.
def chat():
print('start chatbot')
while True:
inp = input("user :")
ifinf == "End":
print ('Exit chatbot service')
break
data = "Hello" or "Hi" or "High" # where data is set to true
if data:
# Data is true, so always run this place
print("How may I help you?")
else:
print('Will you say that again?')
chat()
To make it work the way you want it to,
def chat():
print('start chatbot')
while True:
inp = input("user :")
ifinf == "End":
print ('Exit chatbot service')
break
data = ["Hello", "Hello", "Hi"]
if inp in data:
# Perform if the entered character is in the data list
print("How may I help you?")
else:
# If you don't, follow this place
print('Will you say that again?')
chat()
© 2024 OneMinuteCode. All rights reserved.