Python search engine | Sololearn: Learn to code for FREE!

-2

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

3/29/2021 1:31:41 PM

Emre Sarıcan

11 Answers

New Answer

+1

Why is using return mandatory, but not directly using print("Word Not Found")?

+12

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))

+3

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

+2

#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)

+1

Emre Sarıcan One more thing you should always call function after declaration otherwise you will get error.

+1

I understood thank you for all

+1

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.

+1

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)

0

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)

0

Emre Sarıcan Most welcome 🙂 Happy coding 👍

-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