def search(text, word):
if word in text:
print("Word found")
else:
print("Word not found")
text = str(input())
word = str(input())
print(search(text,word))
此代码返回以下内容:
"Word found
none"
当我使用这个条目时:
"This is some sample text"
"some"
期望的输出是:"Word found"
试试吧。你的函数没有返回值
def search(text, word):
if word in text:
print("Word found")
return word
else:
return "Word not found"
text = str(input())
word = str(input())
print(search(text,word))