import wikipediaapi wiki = wikipediaapi.Wikipedia('en') print("1st page:") w1 = input() while not wiki.page(w1).exists(): print("This page doesn't exist in English Wikipedia. Please, enter an existing page.") w1 = input() print("2nd page:") w2 = input() while not wiki.page(w2).exists(): print("This page doesn't exist in English Wikipedia. Please, enter an existing page.") w2 = input() found = False graph = {w1: -1} level = {w1} last_row = [] while not found: new_level = set() for l in level: page = wiki.page(l) links = page.links if w2 in links: found = True last_row.append(l) for link in links: if link not in graph: graph[link] = l new_level.add(link) level = new_level print(f"There are {len(last_row)} solutions.") for i in range(len(last_row)): print(f'Solution {i+1}') k = last_row[i] while k != -1: print(k) k = graph[k]