我需要一个良好的亵渎过滤器,同时还要有两个可用的输出以及经过硬编码,但它无法识别“是”或“否”
我曾尝试在某些情况下进行真正的循环搜索,但这可能行得通(如果我知道自己在看什么的话),我对编码还很陌生,我刚接触过Java,然后自己换成了python,所以我我不习惯它的工作方式。
one = input('=[Is the teacher good]= ')
if one == "yes":
input('What makes the teacher good? ')
input('How does the teacher teach? ')
input('Are the other students good? ')
elif one == "fuck" or "shit" or "damn" or "bitch" or "crap" or "piss" or
'dick' or "darn" or "cock" or "pussy" or "asshole" or "fag" or
"bastard"
or "slut" or "douche":
print('please dont use profanity')
print()
elif one == "no":
input('Why is the teacher bad? ')
input('What causes the teacher to be bad ? ')
input('Do other people think the teacher is bad? ')
我尝试了上面的代码,它显示no
和yes
是一个坏词?!
=[Is the teacher good]= >?
否
请不要亵渎
答案 0 :(得分:2)
one = input('=[Is the teacher good]= ')
if one == "yes":
input('What makes the teacher good? ')
input('How does the teacher teach? ')
input('Are the other students good? ')
elif one in ["fuck" ,"shit", "damn", "bitch" ,"crap" , "piss" , 'dick', "darn" ,"cock","pussy","asshole","fag","bastard","slut","douche"]:
print('please dont use profanity')
elif one == "no":
input('Why is the teacher bad? ')
input('What causes the teacher to be bad ? ')
input('Do other people think the teacher is bad? ')
你不能写像这样的表达式:
elif one == "fuck" or "shit" or "damn" or "bitch" or...:
这样做:
elif one == "fuck" or one == "shit" or one == "damn" or one == "bitch" or...:
或:
elif one in ["fuck" ,"shit", "damn", "bitch" ,"crap" ,..]: