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.
Simple if/ else statement to determine what team any given person would be on:
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))
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)))