以下是一个示例代码,用于解决包括两个同时不能使用的标题的问题:
def validate_titles(title1, title2):
forbidden_words = ['title1', 'title2'] # 设置禁用的标题列表
if title1 in forbidden_words and title2 in forbidden_words:
return False
else:
return True
# 使用示例:
title1 = input("请输入标题1:")
title2 = input("请输入标题2:")
if validate_titles(title1, title2):
print("标题可使用")
else:
print("标题不可使用")
在上述示例中,我们定义了一个名为validate_titles
的函数,它接受两个标题作为参数。函数内部定义了一个forbidden_words
列表,其中包含禁用的标题。然后,我们检查传入的标题是否都在禁用列表中,如果是,则返回False
,表示标题不可使用;如果不是,则返回True
,表示标题可使用。
在使用示例中,我们通过input
函数获取用户输入的标题,并将它们作为参数传递给validate_titles
函数。最后,根据函数的返回值输出相应的结果。