# 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

10 Likes

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.

3 Likes

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
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!

2 Likes

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)``````
1 Like

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!

1 Like

I believe the reasoning is based on the modulo operator logic. If 27 % 4 is 3, that means there’s three left over after it was evenly divided. If it were evenly divided you would have gotten 0 instead. Assuming the first even division is 4, then the fourth team would be the “0th” team, which is why zero will always be at the end.

Hope this helps

1 Like

10 posts were split to a new topic: Food for thought idea

Easy explanation for food for thought.

Lets say you have 15 players.

Simply assign 1 player to each team and count upwards.

When you assign a new player into a team write down its number, like this.

Team 1 = 0 - 4- 8 - 12
Team 2 = 1 - 5 - 9 - 13
Team 3 = 2 - 6 - 10 - 14
Team 4 = 3 - 7 - 11 - 15

I think the lecture is broken or something?

first:
in Question #3 delete all of your codes and then run the terminal. the question will be marked with check, indication that you answered the question properly. which is wrong since your terminal has no codes or anything. (I tried to input random code and text when I was on Question #3 and it always give me a check mark on question #3)

second:
the best method to answer the question is to use some advance knowledge in programming. which is wrong for me at least, since the knowledge you need to answer it, is on other lecture.

I think question#3 will make more sense on advance lecture like if else, listing, where you’ll need to use modulo operator.

Sir, this shows the error

File “script.py”, line 4
if kid % 4 ==0
^
SyntaxError: invalid syntax

Can you please explain the plausible reason and solution thereof.

This explains it well. Thanks.

I see a lot of responses that are well over thinking this question. I simply did this and the logic seems sound with the results going between 25 - 29 ppl.

my_team = (27 % 4)

print (25 % 4)
print (26 % 4)
print (my_team)
print (28 % 4)
print (29 % 4)

Results:
1
2
3
0
1

Meaning:
person 25 -Team 1
person 26 - Team 2
person 27 - Team 3
person 28 - Team 0
person 29 - Team 1

Having read the comments here are my thoughts too…For me the ‘food for thought’ stood out in the comment hence if the persons next to me are 26 and 28 in a team of 27 people , that means i am part of the persons left without a team and since there are 4 teams that means i am on the 5th team that is incomplete…
I am open to any suggestions that have any other thought.