- 2
Please what is wrong in this code?
text = input() word = input() if ("word found")(search): print("word found") else: print("word not found") print(search(text, word))
10 Answers
+ 3
Sobola Gabriel Pls don't give finished code in the answer. This is a learning app - if we don't allow the OP to write the code, we defeat learning.
Always prefer giving hints to put the OP in the right direction. This allows for real learning.
+ 5
The problem is lack of info in the question. Pls edit it, including:
1. A tag with the language
2. The code purpose
3. The results you found wrong
Help those willing to help you.
+ 2
Chiemerie Ekwueme E.
Are you trying to resolve this using a function, or a simple if/else statement
+ 2
The thing is you ain't using the variables you initialized in the if statement, you should have something like if text == or if text < or if word == or any condition as the case may be, that's missing in the code.
+ 2
Chiemerie Ekwueme E. It's a bit clearer. Pls do the following for you to get real help, without forcing others to guess:
1. Put this explanation, about the code purpose, in the question description. Your explanation in an answer will get lost among the others.
2. Put your code in Code Playground and include a link to it (using "+" button) in the question description. This allows testing, debugging, and keeps the question updated.
That said, there's two visible problems:
The function call syntax in Python is 'function(arguments)', not '(arguments)(function)';
Well, no function 'search'. At least start it.
Now, read about function 'split', and the test 'a in b'. This will help a lot.
If you still have difficulties, first of all, follow the instructions above.
+ 1
The logic in 'if' statement is not written correctly
If you are doing this with a function then you need to provide the full code otherwise it leads to confusion and guesses about the functionality of your code.
+ 1
Ok let me explain.......
The given code should take a text and a word as input and pass 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.
I hope it is clear now
+ 1
text = input();
word = input();
def search(text, word):
text = text.split();
if word in text:
return "Word found";
else:
return "Word not found";
print(search(text, word));
This should solve your question if I got you really.
+ 1
Thank you sirsđ
0
Python can't take two input.