How to make the final project of python for beginners"search engine" with function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to make the final project of python for beginners"search engine" with function?

I made the project using "if~else" statement and the code is :- text = input() word = input() if word in text: print ("Word found") else: print ("Word not found") # I want you guys to make this code again using "function".

23rd Jul 2022, 9:04 AM
No One
4 Answers
+ 3
Function need to be reusable so consider adding parameter to function, like this: text = input() word = input() def search(textForSearch,wordForSearch): if wordForSearch in textForSearch: return "Word found" else: return "Word not found" print(search(text, word)) so now if word and text is diferent we can call same function again, over and over
23rd Jul 2022, 1:27 PM
PanicS
PanicS - avatar
+ 3
Now I understand how to do it using function. def search(): x = "Word found" y = "Word not found" if word in text: return x else: return y x = search() print (x)
23rd Jul 2022, 11:40 AM
No One
+ 2
Read lection about function again, you just need to place your code inside function and return from it not print directly. Than call function with input parameter and print returned result
23rd Jul 2022, 9:16 AM
PanicS
PanicS - avatar
+ 1
Thank you
23rd Jul 2022, 2:44 PM
No One