How to make a program in python using function that find word from a paragraph | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make a program in python using function that find word from a paragraph

It is the last question of python fundamentals

19th May 2021, 9:17 AM
Monu Yadav
Monu Yadav - avatar
23 Answers
+ 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")
19th May 2021, 10:22 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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!
19th May 2021, 9:49 AM
Lothar
Lothar - avatar
+ 3
Post your code first
19th May 2021, 9:24 AM
Atul [Inactive]
+ 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
19th May 2021, 9:52 AM
Atul [Inactive]
+ 3
Rik Wittkopp just for clarification using split function here is optional?
19th May 2021, 10:30 AM
Atul [Inactive]
+ 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
19th May 2021, 10:42 AM
Atul [Inactive]
+ 1
I can't find a course called Python Fundamentals to reference your question. Also, I agree with Atul, you need to show your attempted code so we may understand which part of the concept you are struggling with.
19th May 2021, 9:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Actually I didn't understand the topic making own function that's why I can't understand it
19th May 2021, 9:45 AM
Monu Yadav
Monu Yadav - avatar
+ 1
Thanks for reminding me ok I'll take previous lessons of it than I'll try
19th May 2021, 9:51 AM
Monu Yadav
Monu Yadav - avatar
+ 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)
19th May 2021, 10:03 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
I also think so that it is quite make fun for me to think about and at last get the right answer
19th May 2021, 10:06 AM
Monu Yadav
Monu Yadav - avatar
+ 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.
19th May 2021, 10:06 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks alot I'll got the answer
19th May 2021, 10:27 AM
Monu Yadav
Monu Yadav - avatar
+ 1
I used function in C language but there is quite differ but finally I got it with a certificate
19th May 2021, 10:27 AM
Monu Yadav
Monu Yadav - avatar
+ 1
Atul One of the many joys of Python, you don't need to break down to a list & iterate to see if item in string. text = "this is a test" word = "test" if word in text: print("yippee") PS: Great question, I gave been writing psuedocode and had to check this answer before posting
19th May 2021, 10:37 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
19th May 2021, 10:44 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Monu Yadav When you get the right answer because of your own efforts, then your confidence will soar
19th May 2021, 10:52 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
No it is not python fundamentals it is Python for beginners
19th May 2021, 9:44 AM
Monu Yadav
Monu Yadav - avatar
0
Monu Yadav Looking now
19th May 2021, 9:46 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Yes actually
19th May 2021, 9:47 AM
Monu Yadav
Monu Yadav - avatar