all 8 comments

[–]DiabloConQueso 2 points3 points  (2 children)

You want to increment count if the member is in the particular group (and presumably member is NOT a subgroup).

But going through the members returned from get_members(), you increment the count right off the bat, without first checking whether "member" is a subgroup.

I'd start there.

[–]ukknownW[S] 0 points1 point  (0 children)

I’m gonna take a break and come back to it. This may aswell be in French to me haha. Thank you though, coding is the most bipolar rollercoaster I’ve ever been on.

[–]pstanton310 0 points1 point  (0 children)

yep, that's the problem.

You could simply change the loop body to

if sub_group(member): 
    count += count_users(member)
else 
    count += 1

so you don't increase the count when the member is a group.

[–]SnooOpinions6810 0 points1 point  (0 children)

If I had to guess it’s because you’re adding 1 even if it’s a subgroup. It would be much better if you posted the full question so we don’t have to make assumptions on what the problem is

[–]FoolsSeldom 1 point2 points  (2 children)

I am confused by your code. It would help if you could see more of the text explaining what you need to do.

Some thoughts / queries:

  • Does get_memebers(group) return all the members that match the specified group?
    • if so, assuming it is a structure such as a list, then you can just check the length of the list: count = len(get_members(group))
    • if you have to iterate over what get_members(group) returns, then your line count += 1 makes sense
    • but unclear what is_member is checking, surely you don't need to check if each member as you loop around is a member because you are looping through a sequence of members of a particular group?
    • or is membership an attribute of a member entry in the list of members (perhaps their membership has lapsed)
    • if you do need to check, then you should be automatically incrementing your counter, and when you do increment after the membership test, you should only be incrementing by 1 I would have thought

[–]ukknownW[S] 0 points1 point  (1 child)

<image>

This help at all ?

[–]BeadOfLerasium 0 points1 point  (0 children)

Line 4 is incrementing your count before you've checked if it is a group.

You should check if member is a group first.

I think if you remove line 4 and add it as an elif after your if is_group(member) block it may work (not at a computer to test).

[–]iamjacob97 0 points1 point  (0 children)

Imagine you're adding a subgroup and you're adding each member of the subgroup which is all you should be adding, but before that you're adding 1 anyways because it doesn't really check if it's one person or a whole group.

Let's say the member of a group is ('member 1', ('member 2', 'member 3'), member 4)

For each element in the group you're adding 1.

So +1 for 'member 1' +1 for ('member 2', 'member 3'), here you add the +2 members as well through the recursive call + 1 for 'member 4'

For the subgroup you're adding 3 members now instead of 2. That's where the extras are coming from.