python - 我能知道如何解决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
解决方案
您的 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 ")
推荐阅读
- angular - 在 Angular 中创建服务时 Observable<> 出错
- angular - html2canvas 导出 a4 大小,无论窗口大小如何
- java - 通过指定java版本运行cp命令
- c# - 从 Web API 返回结果时添加两个小数点 .00
- javascript - Fullpage js - 我可以添加另一个仅在移动屏幕上可见的整页部分吗?
- triggers - 在不使用标准 clone() 方法的情况下克隆包含所有字段的机会记录?
- elasticsearch - Kibana 中的强制过滤
- python - 当我运行这个斐波那契数字程序时,我的电脑就挂了
- git - Git 修改之前的提交,该提交已经被错误的更改推送
- php - PHP脚本下载php文件本身而不是给定的文件