0

I am trying to make a program like this I want to detect if there is abusive comment in any of the comment please tell if this is correct way to write a program

c1=input("please enter your comment")

if "click here" or "buy now" or "link" in c1:
    print("this is spam")

else:
    print("thank you for your feedback")
  • 2
    Does this answer your question? [How to test multiple variables against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-single-value) – Ture Pålsson Sep 23 '21 at 05:35

3 Answers3

0

A quick solution:

c1=input("please enter your comment")

restricted_phrases = ["click here", "buy now", "link"]

spam = False 
for p in restricted_phrases:
        if c1.find(p) != -1:
                spam = True
                break
 
if spam: print("this is spam")
else: print("thank you for your feedback")
Jack
  • 101
  • 1
  • 6
0

No,You are doing wrong.

You can to do it like this:

c1=input("please enter your comment")

if ("click here" in c1) or ("buy now" in c1) or ("link" in c1):
    print("this is spam")

else:
    print("thank you for your feedback")
Abhay Kumar
  • 116
  • 1
  • 12
0

What the author of the question wrote was like this:

if ("click here") or ("buy now") or ("link" in c1):
     do something

Therefore the code looks if "click here" or "buy now" is truthy after that it looks if "link" is part of c1. As the string are evaluated as True, the condition will be always true.

To find the best solution I suggest to go to the link mentioned inside the comments.

Perhaps you can use more parenthesis:

 if ("click here" in c1) or ("buy now" in c1) or ("link" in c1):
thomas
  • 381
  • 2
  • 7