Intro
Python is high-level, general purpose programming language. By using python we can create different stuffs like dictionary, mobile application, web application, etc. By using python we can also search about any famous place, person, etc. Like we search in wikipedia, we can get information about any famous places, person etc from python by using wikipedia module.
Wikipedia in python is the library that makes it easy to access and parse data from Wikipedia.
Installation
For the installation of Wikipedia module , Python should be installed in your computer and pip as well. After this all you can open your command prompt or powershell and type
pip install wikipedia
Now Lets Write the program
import wikipedia
Search = input("type that you want to search") #here I want to search about Nepal
result = wikipedia.search(Search)
try:
for sr in result:
print(sr)
print("-----------------------------------")
print(wikipedia.page(sr).summary)
print("******************************************")
print()
except Exception as e:
pass
Lets see how above program is working
First of all we imported the wikipedia module then we asked the user what to search. Then we write result = wikipedia.search(Search). Here we are telling the wikipedia module to search about something we asked the user to type. After this we used the try and except because if there will any error it will not arrive during the program execution. In 4th line we wrote result = wikipedia.search(Search) this will return a list which contains the term related to the user enter. In for loop, for every items in the list are being search in wikipedia and getting the summary of every items in list. Then the program will display the results.
Comments
Post a Comment