Question: Hi, i have this problem in Python: The count_users function recursively counts the amount of users that belong to a group in the company system,

Hi, i have this problem in Python:

The count_users function recursively counts the amount of users that belong to a group in the company system, by going through each of the members of a group and if one of them is a group, recursively calling the function and counting the members. But it has a bug! Can you spot the problem and fix it?

This is the code :

def count_users(group): count = 0 for member in get_members(group): count += 1 if is_group(member): count += count_users(member) return count

print(count_users("sales")) # Should be 3 print(count_users("engineering")) # Should be 8 print(count_users("everyone")) # Should be 18

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!