+ 1
Python search engine
Guys Anybody know how write this!! 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 a function called search(). The search() function should return "Word found" if the word is present in the text, or "Word not found", if it’s not. Sample Input "This is awesome" "awesome" Sample Output Word found
20 Antworten
- 7
Why is using return mandatory, but not directly using print("Word Not Found")?
+ 14
Emre Sarıcan
You need to check word in text but you didn't.
Solution:-
#That is mine try
text = input()
word = input()
def search(text, word):
#for i in word:
if word in text:
a ="Word found"
return a
else:
b = "Word not found"
return b
print(search(text, word))
+ 9
def search(text,word):
if word in text:
print("Word found")
else:
print("Word not found")
return (search)
text = input()
word = input()
search(text, word)
This worked for me try it out.
+ 2
There are two problems
1 - Indentation
2 - you are taking input as word but passed in function as Word.
So try this
text = input()
word = input()
def search(text, word):
if word in text:
print("Word found")
else:
print("Word not found")
search(text, word)
+ 1
def seacrh(text,word) :
if word in text :
print ('Word found')
else:
print('Word not found')
text = input()
word = input()
seacrh(text,word)
done..!
0
Emre Sarıcan
One more thing you should always call function after declaration otherwise you will get error.
0
I understood thank you for all
0
Emre Sarıcan
Most welcome 🙂
Happy coding 👍
0
text = input()
word = input()
def search(text, word)
if word in text:
print("Word found")
else:
print("Word not found")
print(search(text, word))
Important points to note: Always declare variables before creating function
0
#Here is my code try it:
def seacrh(text,word) :
if word in text :
print ('Word found')
else:
print('Word not found')
text = input()
word = input()
seacrh(text,word)
0
I still cant get it
0
text = input()
word = input()
def search(text,word):
if word in text:
print("Word found")
else:
print("Word not found")
search(text, word)
0
you can use this code
text = input()
word = input()
def search(text, word):
if word in text:
a = "Word found"
return a
else :
a = "Word not found"
return a
print(search(text, word))
0
https://code.sololearn.com/WBVBiXD0Su77/?ref=app
Here, working
0
text = input()
Word = input()
def Search(text,word):
if word in text:
a = "Word found"
return à
else
b = "Word not found"
return b
print(search(text, word))
0
text = input()
word = input()
def search(text, word):
if word in text:
print("Word found")
else:
print("Word not found")
search(text, word) #just remove the print, by me :D
- 2
Emre Sarıcan
Here is my code try it:
def seacrh(text,word) :
if word in text :
print ('Word found')
else:
print('Word not found')
text = input()
word = input()
seacrh(text,word)
- 2
Thank youi
- 3
That is mine try
text = input()
word = input()
print(search(text, word))
def search():
for i in word:
if i == word:
a ="Word found"
return a
else:
b = "Word not found"
return b