python-101 icon indicating copy to clipboard operation
python-101 copied to clipboard

Update 42_forty_two.py

Open LegendJurai opened this issue 8 months ago • 1 comments

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'.

LegendJurai avatar Mar 03 '25 13:03 LegendJurai

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!")

asimhusain-ai avatar Sep 24 '25 09:09 asimhusain-ai