How can I determine the numbers for all 4 teams? (Food for thought)

I have seen many solutions to this problem but everyone seems to be ignoring the fact that there is no such thing as TEAM 0.

The solution below takes this into consideration and simply adds 4 to any person whose number is divisible by 4. This will then put them in team 4.

There are 8 examples:

#constructor for team_selector
def team_selector(person_number, number_of_teams=4):

#if persons number is divisible by 4 then put them in team 4
if person_number%number_of_teams==0:
return person_number%number_of_teams+4

If persons number is not divisible by 4 then add them to the team == remainder

else: return person_number%number_of_teams

print(‘Person 1 would be in team’,team_selector(1))
print(‘Person 2 would be in team’,team_selector(2))
print(‘Person 3 would be in team’,team_selector(3))
print(‘Person 4 would be in team’,team_selector(4))
print(‘Person 201 would be in team’,team_selector(201))
print(‘Person 202 would be in team’,team_selector(202))
print(‘Person 203 would be in team’,team_selector(203))
print(‘Person 204 would be in team’,team_selector(204))

If we interpret the question as:

“Calculate the number of people on each team when given the total number of people.”

Then the solution would be:

By all means change the total_number_of_people to any number and it will work.

total_number_of_people=2001
remainder=total_number_of_people%4
if remainder==0:
team1_total=total_number_of_people/4
team2_total = total_number_of_people / 4
team3_total = total_number_of_people / 4
team4_total = total_number_of_people / 4
elif remainder==1:
team1_total = (total_number_of_people / 4)+1
team2_total = total_number_of_people / 4
team3_total = total_number_of_people / 4
team4_total = total_number_of_people / 4
elif remainder==2:
team1_total = (total_number_of_people / 4)+1
team2_total = (total_number_of_people / 4)+1
team3_total = total_number_of_people / 4
team4_total = total_number_of_people / 4
else:

``````team1_total = (total_number_of_people / 4)+1
team2_total = (total_number_of_people / 4)+1
team3_total = (total_number_of_people / 4)+1
team4_total = total_number_of_people / 4
``````

We don’t need to worry that dividing by 4 will give a float. By displaying the answers as integers we eliminate the numbers after the decimal point.(We could have used team?_total=total_number_of_people-1)/4 but displaying as integer makes this unnecessary)

print('The total number of people in team 1 is '+str(int(team1_total)))
print('The total number of people in team 2 is '+str(int(team2_total)))
print('The total number of people in team 3 is '+str(int(team3_total)))
print('The total number of people in team 4 is '+str(int(team4_total)))

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.