Motive There are different types of modules in python which not everyone knows so we thought of introducing them to you guys. Let's start! Note: This is not a tutorial of how to use these but is to show that these modules also exist and if you want to know more you can visit there own page and if you want us to explain leave a comment below. Links to there page are also given below. Hope you found something useful. 1.Wikipedia Yes, there is a module called Wikipedia in python, you can easily install Wikipedia by pip install wikipedia . We cannot rely on this module for advanced use. It was designed for ease of use and simplicity. Learn More Here . Here is a simple example: import wikipedia wikiPython = wikipedia.summary("Python", sentences=2) print(wikiPython) One big disadvantage is that it works only if the interne...
Motive
I am a guy who watches a lot of YouTube videos, there I saw a video that teaches a Linear search in python so I taught to try it myself and make it easier for you to understand. Let's see how it's done.
The Project
First let's make a list of numbers and name the list as list. Then let's make a function called searchFor which takes one parameter called number.
Then:
Here,we create two variables called index and set it to 0 and indexValue to the number at the index in the list(indexValue = list[index]).
After that:
We run a while loop in which if number (parameter) is not equal to the indexValue, we add one to index and the get the value in that index and again check if number is equal to indexValue and continues till we find the number that we are searching for.
Then:
Now we print that the number that we searched for is at this particular index.
The full code:
Now let's test the code:
So now we should get 3 as the index:
This works !!!
If you have any doubts or errors in the program feel free to comment down below and I will respond as early as possible. And if I have made any mistake please correct me in the comment box below. Don't forget to follow us for such python related content.
Comments
Post a Comment