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
3
Answer:
it is not the question of computer
Answered by
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
Chemistry,
4 months ago
Math,
4 months ago
Computer Science,
4 months ago
Social Sciences,
9 months ago
Math,
1 year ago
Math,
1 year ago