I’m new to django python so the if makes me feel confused. Please help me!
Im trying to make a IF condition for Facebook chat bot API. The whole function is when a user sends something in the Facebook chat, my bot will remove all punctuations, lower case the text and split it based on space.
After that he will pick a joke from json list with the keyword he got. A quick reply with 2 buttons “Yes” and “No” is also sent to user with the joke.
It also checks if the keyword is absent. Now I want that when user types “No” in the chat, my bot will send something back like “Then not”. What did I do wrong here?
strong texttokens = re.sub(r"[^a-zA-Z0-9s]", ' ', recevied_message).lower().split()
joke_text = ''
for token in tokens:
if token in jokes:
joke_text = random.choice(jokes[token])
.... some code
send_message(fbid, joke_text)
quick_text = "Do you want another joke? "
send_quick_reply_message(fbid, quick_text)
break
if not joke_text:
joke_text = "I didn't understand! "
"Send 'stupid', 'fat', 'dumb' for a Yo Mama joke!"
send_message(fbid, joke_text)
if 'No':
joke_text = "Then not"
send_message(fbid, joke_text)
3
Answers
is always true, you probably want to be checking if something == ‘No’?
I think this code have a problem
What is ‘No”? You have to compare something with “No”.
And also this
if
condition is on wrong indentation level.‘No’ is a string.
always return True.