Food for thought question?

What the whole exercise meant to show was application of modulo in other situations creatively. In the specific question the number of children is unknown and don’t try to figure out how many total children are there as it is unnecessary to understanding the lesson.
Let us assume there were 16 children ( don’t mind the number it is just for explanation and not the actual figure) and write down numbers 1 to 16 on a piece of paper. Remember the aim of the exercise is to establish what team out of the 4 a child is to be placed, not how many are in a team. Since there are only 4 teams, the divisor we use is 4. If you follow on a piece of paper you will understand that the first 4 children, denoted by numbers 1,2,3 and 4 will be in the corresponding teams(i.e Team 1, Team 2, Team 3 and Team 4). Now proceed to place child number 5 in Team 1, child number 6 in Team 2, child number 7 in Team 3, and child number 8 in Team 4. Do this for all the 16 numbers (children). If you were to use modulo here, the remainder is:
Child 5 = 1
Child 6 = 2
Child 7 = 3
Child 8 = 0
Child 9 = 1
Child 10 = 2
Child 11 = 3
Child 12 = 0
Child 13 = 1
Child 14 = 2
Child 15 = 3
Child 16 = 0
The modulo answer/remainder corresponds to the Team the child is allocated. Note, that all the numbers divisible by the divisor in our case 4 result in 0. So a return of 0 means the child is allocated in the last group usually the divisor, team number 4.
Therefore in relation to the exercise, you are the 27th child out of an unknown number of children. 27%4 results in 3( the remainder) which is the team you are in. This is not your number on the team or how many out of the team, but just the team you are in. If you use the pen and paper method, you will see the logic.Therefore you cannot accurately deduce how many total children they are, but by knowing the number a child is allocated you will know which team he/she is allocated.
It also answers the question that result of a modulo operation can never be larger than the divisor. It’ll always end up being one less the value of the modulo and then becomes 0 if 1 is added to the number being divided.

Hope this helps someone.
B.S

1 Like

I’d like to point out that some of us are here to learn programming from the ground up. I personally have never used python, or have had any programming experience. Many people offered solutions such as iteration over a range. The exercise assumes a knowledge of programming and python in order to continue, seems less than instructive to leave individuals stuck. There is not even a are you stuck type thing to help us through.

1 Like

Wow, elegant code! Thank you

Agreed - “food for thought” here had me thinking about whether or not the rest of this path is going to be as disheartening. Like, here is how to do addition, now food for thought: algebra.

All of you count off, and you get number 27.
That’s mean 27+you=28

Hi guys i wrote a simple and beautiful code to resolve this excersise and i would like to share it with you i know there might be a shorter but more complex way to do it if you know one please share it with me i would gladly appreciate, here is the code:

my_team = (27 % 4)
print ("My team number is: " + str(my_team))
team_person_26 = (26 % 4)
team_person_28 = (28 % 4)
print("The 26th person is on team number: " + str(team_person_26))
print("The 28th person is on team number: " + str(team_person_28))

team_0 =
team_1 =
team_2 =
team_3 =

for i in range(29):
if i % 4 == 0: team_0.append(i)

print("Team 0 members are: ", team_0)

for i in range(29):
if i % 4 == 1: team_1.append(i)

print("Team 1 members are: ", team_1)

for i in range(29):
if i % 4 == 2: team_2.append(i)

print("Team 2 members are: ", team_2)

for i in range(29):
if i % 4 == 3: team_3.append(i)

print("Team 3 members are: ", team_3)


which produces the output:


My team number is: 3
The 26th person is on team number: 2
The 28th person is on team number: 0
Team 0 members are: [0, 4, 8, 12, 16, 20, 24, 28]
Team 1 members are: [1, 5, 9, 13, 17, 21, 25]
Team 2 members are: [2, 6, 10, 14, 18, 22, 26]
Team 3 members are: [3, 7, 11, 15, 19, 23, 27]

let me know if this is helpful or have questions.

Some of this will seem unnecessarily long to the logically adept. I want to make sure I’m giving a thorough explanation of how I found the answer to this question to anyone who is confused. The answer wasn’t immediately obvious to me, and took some persistence, so I wanted to share what I learned. Here goes.

Question 3
Food for thought: what number team are the two people next to you (26 and 28) on? What are the numbers for all 4 teams?

Discussion
There are two questions here:
3.1. What number team are the two people next to you (26 and 28) on?
3.2. What are the numbers for all 4 teams?

Question 3.1: What number team are the two people next to you (26 and 28) on?
You need to use the modulo function to find the teams of numbers 26 and 28, respectively. Recall there is a total of four teams.

Solution
For this question, you will run two modulo calculations using the number four as your divisor. They’ll look like this:
print(26 % 4)
Note: The solution is 2, so person number 26 is on Team 2.

print(28 % 4)
Note: The solution is 0, so person number 28 is on Team 4. We know this because there is no remainder, where a remainder of 1 represents Team 01 and so on.

Question 3.2: What are the numbers for all 4 teams?
Modulos are your friend here. Try looking for patterns.

Solution
Start with a simple calculation like this:
print(1 % 4)

The solution is 1, indicating person number 1 belongs in Team 1. We know there are only four teams, and we start back at Team 1 after someone has been counted for Team 4. That means every fifth person after person 1 will be in Team 1.

Team 1 = 1, 5, 9, 13, 17, 21, 25

The same principle applies to Teams 2 through 4. Every fifth person.

Team 2 = 2, 6, 10, 14, 18, 22, 26
Team 3 = 3, 7, 11, 15, 19, 23, 27
Team 4 = 4, 8, 12, 16, 20, 24, 28

Hopefully this helps someone!

Here is how I did it.


create a numbers variable that will store the total number of people to be divided into teams
numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]
or simply
numbers = range(1,29)

Create four arrays that will be used to store team members
team_1 =
team_2 =
team_3 =
team_4 =

loop through the range and perform the modulo operation on each number to determine which team to append to
for n in numbers:
if n % 4 == 0: team_1.append(n)
if n % 4 == 1: team_2.append(n)
if n % 4 == 2: team_3.append(n)
if n % 4 == 3: team_4.append(n)
nb: the ‘if statements’ after the ‘for loop statement’ should be indented

#print the teams
print("team 1: " + str(team_1))
print("team 2: " + str(team_2))
print("team 3: " + str(team_3))
print("team 4: " + str(team_4))
the str() method, converts the array to a string so you are able to concatenate with another string



the result should be
team 1: [4, 8, 12, 16, 20, 24, 28]
team 2: [1, 5, 9, 13, 17, 21, 25]
team 3: [2, 6, 10, 14, 18, 22, 26]
team 4: [3, 7, 11, 15, 19, 23, 27]

my_team = 27 % 4

print(my_team)

t1 = 26 % 4
t2 = 28 % 4

print(t1, t2, my_team)

2 0 3 was result

team_players=range(0,28)
Team_1 = [num+1 for num in team_players if num %4 == 0]
Team_2 = [num+1 for num in team_players if num %4 == 1]
Team_3 = [num+1 for num in team_players if num %4 == 2]
Team_4 = [num+1 for num in team_players if num %4 == 3]

print("Team 1: ",Team_1)
print("Team 2: ",Team_2)
print("Team_3: ",Team_3)
print("Team_4: ",Team_4)

You can use the f string in Python 3 for concatenation without the need to convert anything.

i.e.
team_26 = 26 % 4
print(f"{team_26} is the team for number 26")

I wrote the following code to show which kid is on which team if there were 28 kids - so you can just change your range max to any number of kids. Also Python is zero-based so had to set the range and also add 1 to the team #.

for i in range(1, 28):
Team = i % 4 + 1;
print(‘Kid#’, i, ‘Team#’, Team )

Hope this helps!