23 ответов
+ 1
So you need to find if a word is in a text via a function.
We will need 2 variables to get started.
text = input() #this is a test
word = input() # test
This sets us up to look for "test" in the sentence "this is a test"
So, a simple if / else statement will determine the result.
if word in text:
print("yippee")
else:
print("Boo")
+ 4
Monu Yadav ,
if you have trouble in solving this exercise, it could be that your experience in python does currently not meet the requirements of the exercise. so you may go back and repeat some lessons, do sone basic and simple exercises in coding and then try it again.
please be patient, learning in coding takes some time. ( remember that you have started the python tutorial 2 months ago, and you try now to continue and finish)
it would be great if you could share your attempt here.
happy coding and good success!
+ 3
Post your code first
+ 3
You can use functions in python like this
def func(parameters)
//Codes
Return value
Using the function func(input the parameters)
Lothar and Rik Wittkopp correct me if I am wrong
+ 3
Rik Wittkopp just for clarification using split function here is optional?
+ 3
Rik Wittkopp thanks I am a fan of your gentle behaviour. I don't know python that much because in java it's mandatory to use split function for it
+ 1
Actually I didn't understand the topic making own function that's why I can't understand it
+ 1
Thanks for reminding me ok I'll take previous lessons of it than I'll try
+ 1
Monu Yadav
I also had a lot of trouble trying to understand functions, but now they are one of my favourite's
I like to think that functions are like algebra.
Example:
x + y = z
Which is similar to:
def sum(x,y):
return (x+y)
z = sum(4,7)
print(z)
+ 1
I also think so that it is quite make fun for me to think about and at last get the right answer
+ 1
Monu Yadav
The trick with functions is that you need to define the actions that will happen upon the arguments, then you MUST call the function with your defined arguments to get an output.
+ 1
Thanks alot I'll got the answer
+ 1
I used function in C language but there is quite differ but finally I got it with a certificate
+ 1
Monu Yadav
Not quite correct!
Read through carefully, remember that function code is self contained.
Search (x,y):
if x in y:
print("yippee)
search(word, text)
# x = word, y = text
x & y are placeholders for your arguments to the function
+ 1
Monu Yadav
When you get the right answer because of your own efforts, then your confidence will soar
0
No it is not python fundamentals it is Python for beginners
0
Monu Yadav
Looking now
0
Yes actually