+ 6

search engine challenge

what is wrong in my code,I am not getting right answer. Pls. help me out text = input() word = input() def search(text,Word): if Word in text: print("Word found") else: print("Word not found") search(text,Word)

13th Apr 2021, 7:06 AM
Sachin
Sachin - avatar
19 ответов
+ 18
text = input() word = input() def search(text,word): if word in text: return("Word found") else: return("Word not found") print(search(text,word)) maybey like thes
13th Apr 2021, 11:39 AM
Soulaimane Sarouri
Soulaimane Sarouri - avatar
+ 7
Sachin 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)
13th Apr 2021, 7:14 AM
A͢J
A͢J - avatar
+ 5
No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers. Let’s save some time by creating a program to do the calculation for you! Take a number N as input and output the sum of all numbers from 1 to N (including N). Sample Input 100 Sample Output 5050 Explanation: The sum of all numbers from 1 to 100 is equal to 5050.
1st May 2021, 11:59 AM
Balogun Gabriel
Balogun Gabriel - avatar
+ 3
Sachin Why did you write return? Why you don't just call function without return?
13th Apr 2021, 7:08 AM
A͢J
A͢J - avatar
+ 3
I know it and i completed it This is how you need to do it Only 6 lines simple text = input() word = input() if word in text: print("Word found") elif word not in text: print("Word not found")
11th Jun 2021, 1:31 PM
Amrin Liana
Amrin Liana - avatar
+ 2
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)) #not at all!
10th May 2021, 7:11 PM
RED
RED - avatar
+ 2
def search(text, word): # look whether the word is in the text if word in text: print('Word found') else: print('Word not found') text = input() word = input() search(text, word)
13th May 2023, 2:29 AM
Vaibhav
Vaibhav - avatar
+ 1
No need to return search(text,Word) otherwise it will become recursive function.Just return. And also you forgot to call the function: https://code.sololearn.com/cu5f8ltJeiJp/?ref=app
13th Apr 2021, 7:12 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
The future is now thanks to science No need to write return if you are not returning any value and just printing value.
13th Apr 2021, 7:17 AM
A͢J
A͢J - avatar
+ 1
"""If you use print() in the function, it will print when word is found and then test it twice so it produces a "word found" and "none", or it produces "word not found" and "none" Instead of using print inside the function, use return. """ text = input() word = input() def search(x, y): if y in x: return 'Word found' else: return 'Word not found' print(search(text, word))
1st Oct 2022, 12:47 PM
Theodore
0
By mistake,but without return there is no output
13th Apr 2021, 7:10 AM
Sachin
Sachin - avatar
0
The future is now thanks to science I never heard it is good to write without any reason.
13th Apr 2021, 7:21 AM
A͢J
A͢J - avatar
0
Feel like stupid. Tried to find word in search ((( not in text(((
15th Apr 2021, 6:22 PM
Irina Losnikova
Irina Losnikova - avatar
0
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))
21st Jun 2021, 10:07 AM
MD Imteyaz
MD Imteyaz - avatar
0
This worked fine #your code goes here text = input() word = input() def search (text, word): if word in text: print ("Word found") else: print ("Word not found") search(text, word) #remove the last print, 100%working
11th Dec 2021, 2:42 PM
JAMES MUTUNE
JAMES MUTUNE - avatar
0
text = input() word = input() def search(text, word): if word in text: print("Word found") else: print("Word not found") search(text, word) This worked for me 100%!!
9th Jan 2022, 6:32 PM
Francisco José García Soto
Francisco José García Soto - avatar
0
def search(text, word): x="Word found" y="Word not found" if word in text: return x else : return y text = input() word = input() print(search(text, word)) Works for sure..!
23rd Aug 2022, 12:57 PM
Tharun Kumar Reddy
- 1
the most simple code: text=input('Enter the text: ') word=input('Enter the word you want to search: ') t=text.split() c=0 for i in t: if(i==word): c+=1 if(c!=0): print('found') else: print('not found')
21st Dec 2021, 5:51 PM
SANVIKA
- 2
Hey, help me out pls. I know that this way of solving is overcomplicated, but i wonder why this code not working? if you run it, it will additoinally print "None" on the new line. And i dont get were from it appeared? def search(text, word): if text.count(word) >=1: return(print("Word found")) else: return(print("Word not found")) text = input() word = input() print(search(text, word))
20th Apr 2021, 1:25 PM
Вячеслав Ершов
Вячеслав Ершов - avatar