+ 1
Which string functions do I use in the "Search Engine" project of python?
12 Answers
+ 1
It is totally fine. You're code is correct, just get the input given by the challenge
Because in challenges, we have to get the input to meet the expected output.
In this challenge, it gives 2 of inputs (2 lines) which are the text and the word to find.
First, let us get the input and assign the input value to variable.
text = input()
word = input()
Additional, we don't need to print again while calling the function as the output is already printed inside.
https://code.sololearn.com/cDY4avL3b0zG/?ref=app
+ 4
You can just use the 'in' operator to find if a word is in the text.
Example:
print("Hello" in "Hello World")
>> True
+ 1
Using lambdas:
text = input()
word = input()
search = lambda text, word : 'Word found' if word in text else 'Word not found'
print(search(text, word))
Without lambdas:
text = input()
word = input()
def search(text,word):
return 'Word found' if word in text else 'Word not found'
print(search(text, word))
0
I still need some detailed explanation in the "Search Engine" project. I can't get thru
0
Sarvam Fating We're ready to help, just show us your code attempt so far so we may know the problem. Thanks.
0
Thanks I'll post it in a while
0
def search(text,word)
if (text.count(word)==1)
print("Word found")
else:
print("Word not found")
print(search(text,word)
I'm sorry if I've messed it up big time, I'm totally new at coding đ
0
Thank you sooo much đ„șâ€ïžI'll keep that in mind, have a good day
0
Sarvam Fating I forgot to mention. In our 'if' condition, we can just use the 'in' operator to check if that string is inside the other string.
( See the code 'Your Code 159' )
Though your condition 'text.count(word) == 1' is almost right, just have to make it 'word.count(text)' adjust it a little but because the substring may appear 2 or more times.
if (word.count(text) >= 1)
0
Sarvam Fating You're Welcome! You too, Have a Good Day!
0
Yes I'll check it out
0
Thank you so much , the code worked perfectly