def transition_model(corpus, page, damping_factor):
    """
    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    """
    distribution = dict() #Create a dictionary for the probability distribution
    all_pages = []
    links = list(corpus[page]) #All pages linked by current page
    for u in corpus:
        all_pages.append(u)

    #If the current page does not link to any other pages, all pages are equally likely
    if len(links) == 0:
        print("Current Page does not have any links")
        probability = 1.0 / len(all_pages)
        for current_page in all_pages:
            distribution[current_page] = probability
        return distribution

    damping_probability = damping_factor / len(links) #Probability that a linked page will be selected
    nondamping_probability = (1.0 - damping_factor) / len(all_pages) #Probability that a page will be randomly selected

    for current_page in all_pages:
        distribution[current_page] = nondamping_probability

    for current_page in all_pages:
        if current_page in links:
            distribution[current_page] = distribution[current_page] + damping_probability

    return distribution