Computer Science, asked by agarwalnaveen75, 9 months ago

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?
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

Answers

Answered by ridhiri
3

Answer:

it is not the question of computer

Answered by shajjadhossainseam13
7

Answer:

def count_users(group):

 count = 0

 for member in get_members(group):

   count += 1

   if is_group(member):

     count -= 1

     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

Explanation:

There we need to minus the extra term

Similar questions