python-101
python-101 copied to clipboard
Update 42_forty_two.py
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'.
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!")