0

Search engine -python challenge

https://code.sololearn.com/cQsvfP3sGu8y/?ref=app Aim of the program is to check for a word in a given sentence and print found if it's present else not found I'm not sure where I messed up pls take a look guys!!

2nd Feb 2021, 12:04 PM
THIRU KUMARAN T R
THIRU KUMARAN T R - avatar
31 Respostas
+ 28
#The Easiest Way To Solve It text = input() word = input() def search(text, word): if word in text: return("Word found") else: return("Word not found") print(search(text, word))
2nd Feb 2021, 5:49 PM
ARNAV SINGH KAINTH
ARNAV SINGH KAINTH - avatar
+ 14
Search engine Python challenge text = input() Word = input() def search(text,Word): if Word in text: print("Word found") else: print("Word not found") search(text,Word)
1st Mar 2021, 5:27 PM
Chaitu
Chaitu - avatar
+ 4
If yu wanna perform addition on global variable like c you need to access it using global keyword to change it's value . c=0 def search(text,word): t=text.split() for i in t: if i==word: global c c+=1 text = input() word = input() search(text,word) if c==0: print("Word not found") else: print("word found")
2nd Feb 2021, 12:10 PM
Abhay
Abhay - avatar
+ 3
[Additional answer] Yes, here is a possible shorter approach: def search(text, word): return word in text text = input().split() word = input() x = search(text, word) if x: print("Word found) else: print("Word not found") - - - - - - - - - - - - - - - - - Or just simply like this (my ver.) text = input() print("Word found" if input() in text else "Word not found") https://code.sololearn.com/c0DH2TKULpLK/?ref=app https://code.sololearn.com/cbukdYd3H3XR/?ref=app
2nd Feb 2021, 1:00 PM
noteve
noteve - avatar
+ 3
text = input() word = input() def search(): if word in text: print('Word found') return else: print('Word not found') search()
9th May 2021, 3:13 AM
Daniel Alarcón S
Daniel Alarcón S - avatar
+ 3
Maybe shortest way? def search(text, word): if word in text: print("Word found") else: print("Word not found") search(input(), input())
28th Oct 2021, 5:58 PM
Mészáros Árpi
Mészáros Árpi - avatar
+ 2
Arnav Singh Kainth Thank you bro!!
4th Feb 2021, 12:20 PM
KSnamAce
KSnamAce - avatar
+ 2
Try don't copy it !!! def search(text, word): if word in text: return("Word found") else: return("Word not found") text = input() word = input() print(search(text, word))
25th Aug 2021, 11:01 AM
Rayen Boussayed Mohammed Amin
Rayen Boussayed Mohammed Amin - avatar
+ 1
Is there any other shorter approach
2nd Feb 2021, 12:20 PM
THIRU KUMARAN T R
THIRU KUMARAN T R - avatar
+ 1
Cyan Thank you bro!!
2nd Feb 2021, 12:39 PM
THIRU KUMARAN T R
THIRU KUMARAN T R - avatar
+ 1
Also I'd recommend learning Regular Expressions (RegEx) if you're interested in getting into these types of projects. RegEx helps a lot with string identification and it's really handy
2nd Feb 2021, 4:24 PM
Arxalier
Arxalier - avatar
+ 1
Arxalier Thanks bro I've learned some of the expressions in Regex .Soon will try to implement myself in upcoming projects !!
3rd Feb 2021, 2:49 AM
THIRU KUMARAN T R
THIRU KUMARAN T R - avatar
+ 1
KSnamAce No Need Bro. I Will Always Help You. Also, Can you please follow me.
4th Feb 2021, 12:30 PM
ARNAV SINGH KAINTH
ARNAV SINGH KAINTH - avatar
+ 1
text=input() word=input() def search(text,word): c=0 array=text.split() for i in array: if i==word: c+=1 else: c+=0 return c def compare(c): if c>=1: print('Word found') else: print('Word not found') compare(search(text,word))
12th Feb 2021, 4:20 AM
Brian MacFarlane
Brian MacFarlane - avatar
+ 1
text = input() word = input() def search(text,word): if word in text : return ("Word found") else: return ("Word not found") print(search(text, word))
8th Jun 2021, 12:45 PM
Vidhi Jain
Vidhi Jain - avatar
+ 1
text = input() Word = input() def search(text,Word): if Word in text: print("Word found") else: print("Word not found") search(text,Word)
17th Jun 2021, 5:34 PM
Dinujaya Jayawardana
Dinujaya Jayawardana - avatar
+ 1
why yall so big brain
16th Sep 2021, 12:23 PM
Dhruv
Dhruv - avatar
+ 1
def search(text): if word in text: return("Word found") else: return("Word not found") text = input() word = input() print(search(text))
8th Nov 2021, 11:05 AM
GAMASU. SRI DEEPTHI SWARUPA
GAMASU. SRI DEEPTHI SWARUPA - avatar
+ 1
Easiest for me: text = input() word = input() if word in text: print("Word found") else: print("Word not found")
25th Sep 2022, 8:40 PM
Jesus Cardenas
0
text = input() word = input() def search(text, word): if word in text: return "Word found" else: return "Word not found" print(search(text, word))
4th Feb 2021, 8:36 PM
AL-Mahdi Ait-ounzar
AL-Mahdi Ait-ounzar - avatar