Python program that uses the Wikipedia package to search for a term on Wikipedia and display the summary.

Program Source Code:

import wikipedia

Ask the user for input

search_term = input(“Enter a term to search on Wikipedia: “)

Search for the term on Wikipedia

wikipedia.set_lang(“en”) # Set the language to English
page =
summary = page.summary
except wikipedia.exceptions.PageError:
print(“Sorry, no page on Wikipedia matches your search term.”)

In this program, we first import the wikipedia package. We then ask the user for input of a term to search on Wikipedia.

We use a try block to catch any errors that might occur while searching for the term. We set the language to English using the set_lang method, then call the page method with the search term as an argument. This returns a wikipedia.WikipediaPage object, which we can use to access information about the page, including the summary.

If no page on Wikipedia matches the search term, a wikipedia.exceptions.PageError will be raised. We catch this error and print a message to the user.

Note that you may need to install the wikipedia package using pip install wikipedia if you haven’t already done so.

About the author


Hey, DDSRY is a Computer Science Student, Python Programmer, Indian Python Podcaster, and Content Creator.

DDSRY Help Students To Learn Python Programming Language on Social Media.

This Website ( is committed to helping students to Learn Python Programming Language in the easy and best way by DDSRY.


View all posts