0

I'm making a basic program to detect certain words from a string and mark the message as SPAM if the string contains the spam keywords but ran into a problem. The compiler doesn't detect it as spam unless I input the exact same strings.

Here's the code :

text = input("text : ")

if(text == 'make a lot of money' in text) or (text == 'buy now'in text) or (text == 'subscribe this 'in text) or (text =='click link' in text):
    print("SPAM")
else:
    print("OKAY")
Muhammad Mohsin Khan
  • 1,444
  • 7
  • 16
  • 23

3 Answers3

3

That' because you're comparing with equals:

text == 'make a lot of money' in text

instead just use the in command:

'make a lot of money' in text

will yield True if the text contains that string

geanakuch
  • 778
  • 7
  • 13
  • 24
0

You're not using correct syntax for if statement, please use this:

text = input("text : ")

if 'make a lot of money' in text or 'buy now' in text or 'subscribe this' in text or 'click link' in text:
    print("SPAM")
else:
    print("OKAY")
Vishwa Mittar
  • 378
  • 5
  • 16
0
text = input("text : ")

if('make a lot of money' in text) or ('buy now'in text) or ('subscribe this' in text) or ('click link' in text):
    print("SPAM")
else:
    print("OKAY")

OR

text = input("text : ")
spam_phrases = ['make a lot of money','buy now','subscribe this','click link']

for phrase in spam_phrases:
    if phrase in text:
        print("SPAM")
        break
else:
    print("OKAY")
wekular
  • 91
  • 9