镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Update 42_forty_two.py - #116

Open
LegendJurai wants to merge 1 commit into
codedex-io:mainfrom
LegendJurai:patch-5
Open

LegendJurai wants to merge 1 commit into
codedex-io:mainfrom
LegendJurai:patch-5

Conversation

@LegendJurai

Copy link
Copy Markdown

Actually, the '.search' command doesn't work (in my code editor). And in the instructions there was an external link which also says it should be '.summary'.

Actually, the '.search' command doesn't work (in my code editor). And in the instructions there was an external link which also says it should be '.summary'.
@asiimhusain

Copy link
Copy Markdown

import wikipedia

wikipedia.set_lang("en")
topic = input("Enter a topic: ").strip()

try:
print("\nSummary:\n", wikipedia.summary(topic, sentences=3))
print("\nRelated articles:", ", ".join(wikipedia.search(topic)[:5]))
except wikipedia.exceptions.DisambiguationError as e:
print("Multiple options:", ", ".join(e.options[:5]))
except wikipedia.exceptions.PageError:
print("Page not found!")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants