+ 1
Youâre working on a search engine. Watch your back Google! The given code takes a text and a word as input and passes them to
text = input () word = input() def search(text,word): If word==text: Print("Word found) else: print("Word not found")
7 Answers
+ 3
You need to use in operator to determine whether or not a string is a substring of another string.
== is used for comparing values.
Also, you're missing to call search function at the end.
+ 3
Alabi Ayodele the code defines the search() function but never calls it.
In the search() function, it mistakenly compares for an exact match of the two strings, whereas the task is to determine whether the word is found within the text. The text may have other words in it as well.
Print should not be capitalized.
+ 2
Alabi,
Please note the use cases of relevant tags in the post. It's important because it is used by SoloLearn search engine to classify topic of discussion, and proper tags allows better searchability.
https://code.sololearn.com/W3uiji9X28C1/?ref=app
+ 2
Alabi Ayodele For unexplained reasons, you replaced the text "Word found" with a recursive call. Restore the text and it should work.
+ 1
Alabi Ayodele that is better, but still it needs to call the function. Add this line:
search(text, word)
0
text = input()
word = input()
def search(text, word):
if word in text:
print(search (text, word))
else:
print("Word not found")
0
text = input()
word = input()
def search(text, word):
if word in text:
print(search(text, word))
else:
print("Word not found")
search(text, word)
# I did this still not working