In a social networking service a user has friends the friend

In a social networking service, a user has friends, the friends have other friends, and so on. We are interested in knowing how many people can be reached from a person by following a given number of friendship relations. This number is called the \"degree of separation\": one for friends, two for friends of friends, and so on. Because we do not have the data from an actual social network, we will simply use an average of the number of friends per user. Write a recursive function def reachablePeople(degree, averageFriendsPerUser) Use that function in a program that prompts the user for the desired degree and average, and then prints the number of reachable people. This number should include the original user. Please do in Python and write a main.

Solution


#runs the program
def main():
    degree = int(input(\"Enter the degree: \"))
    averageFriendsPerUser = int(input(\"Enter the average friends per user: \"))

    print(str(reachablePeople(degree, averageFriendsPerUser)) + \" people are reachable with those values.\")


# Calculates the number of reachable people
# @param degree - the number of degrees, averageFriendsPerUser - the average friends per user
# @return - the number of reachable people
def reachablePeople(degree, averageFriendsPerUser):
    numReachable = 1
    for num in range(degree):
        numReachable *= averageFriendsPerUser
        numReachable += 1
    return numReachable

# Start the program
main()

In a social networking service, a user has friends, the friends have other friends, and so on. We are interested in knowing how many people can be reached from

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site