首页 > 解决方案 > 我能知道如何解决python中以下代码的错误吗

问题描述

我能知道如何解决python中以下代码的错误吗

text = input("Enter your text here :")
if text.find("make a lot of money" !=-1 or "Make a lot of money"!=-1 or "MAKE A LOT OF MONEY"!=-1):
    print("This Text contains spam words ")

错误:

Enter your text here :MAKE A LOT OF MONEY

Traceback (most recent call last):
  File "e:\Python Course with Notes\Practice set\Chapter 6\Chap_6_pr_3.py", line 2, in <module>
    if text.find("make a lot of money" !=-1 or "Make a lot of money"!=-1 or 
"MAKE A LOT OF MONEY" !=-1):
TypeError: must be str, not bool

标签: python

解决方案


您的 find 函数格式错误,您需要像这样评估函数的结果

text = input("Enter your text here :")
if (text.find("make a lot of money") !=-1) or (text.find("Make a lot of money") !=-1) or (text.find("MAKE A LOT OF MONEY"!=-1):
    print("This Text contains spam words ")

推荐阅读