# Food for thought question?

I will let you in on some of the thought process that we develop as we mature, or gain confidence, in coding for a particular language, in this case, Python.

Let’s take it back to the first weird statement we encountered in programming…

``````a = a + 1
``````

Once we learn that the expression on the right is being assigned to the variable on the left it all makes sense. But it was weird on that first encounter.

We’ve given a variable a particular state, but then later we alter that state based on its current state. Make sense?

That’s what is happening in the two lines that define the same variable. The first line defines, the second line refines it, using its current values. It’s a morphing from one object form, a list, to another object form, a dictionary and allowing it to keep its name.

One will not get into the mechanics above. There are ranges, by the way, two of them. It is possible to construct those for loops in block syntax, which I would suggest you do to see how they play out. They are nested, so bear that in mind.

Hold off playing with this too much while you get under way. Course material and progressing forward should come first. This will still be here when you come back around. Happy coding!

1 Like

Than you for that. I am really enjoying the python lessons (more than sql) so far.

Ben Ritter

1 Like

I just signed up for Codecademy Pro and just wanted to voice my opinion that this ‘food for thought’ is extremely confusing and I still don’t understand it. I understand how the modulo works by giving you the value of the remainder of a division but how this works in correlation to a hypothetical team I’m just not understanding.

“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?” In my opinion, this is a horribly written exercise for new students like myself that does more to confuse than to explain the core topic.

The term, ‘modulo’ derives its name from ‘modulus’ or repeated modulations, much like a sine wave. From one wave to the other, we see the same `y-values` repeated indefinitely. This is the same thing happening in this lesson. There are only four teams and we wish to divide up all the players evenly into the four teams. That suggests the total number of players is divisible by 4 but it is not a factor in the grand scheme. Some teams may have an extra player when the delegation is completed.

A modulo completion set can never have more values than the divisor. In this case the divisor is `4`, so there can only ever be,

``````0, 1, 2, or 3
``````

as the modulo. Three out of every four divisions will have a non-zero remainder.

If we don’t like the team number, `0`, we can make that into team number, `4`.

``````y = x % 4 or 4
``````

That gives us, `1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, ...`.

I understand, it’s just the way that the question was initially phrased that was confusing.
Perhaps Codecademy can rewrite it in a way that makes it more clear what the goal of the exercise is.

Going through this entire thread I cannot find a link to the exercise. Perhaps it would be best if we start from there and then work toward the problem in narrative, diction or general directions. Please post a link to the exercise, thanks.

1 Like

Python offers a companion to the division operator called the modulo operator.

This is not exclusively a Python offering. All programming languages utilize the mathematical principle of the Law of Remainders. It’s the basis of synthetic division in mathematics.

The first question asks us what team we will be on if our number is 27.

``````27 % 4  =>  3
``````

That’s the remainder of 27 over 4. So we’re on team 3.

Given our understanding so far, the adjacent players are one more and one less than me. One less is `2`; one more is `4`, which does not exist, so it must default to `0`. No math involved.

1 Like

Thank you for the explanation mtf

1 Like

How to code the computer to print the numbers which are in each team?

Do you mean like this?

``````Team 1: [1, 5, 9, 13, 17, 21, 25]
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]
``````

Going through this thread has been an interesting look into how other folks have approached this exercise. And a thank you to @mtf for sharing your thoughts and wisdom along the way too!

Just to share my own process here on answering the food for thought questions, I’m not great at working out math logic in my head so I went straight to just coding the answers like I was using a calculator, doing that helped me get a better understanding of what was being asked and helped me approach the last question.

Full disclosure I have some exposure to coding and python previously too so that has likely influenced my approach as well. Also, I operated on the assumption that the total number of people in the group was 28.

``````my_team = 27 % 4
print(my_team)
left_team = 26 % 4
print(left_team)
right_team = 28 % 4
print(right_team)

member = 1
while member <= 28:
team = member % 4
print("Member #", member, "is in group", team)
member += 1
``````
1 Like

Below please see my “solution” to the question. I realize the inelegant and primitive nature of such a “brute force” approach is anathema to the essence of our education. I will be the first to say I am certainly not “proud” of my work . However I was unable to determine a more effective answer. Sometimes your role in life is to be a “bad example” -I’ve had plenty of experience with this, so perhaps my crude construction can teach someone what NOT to do…

print ("Team 1 includes: ")
for n in range(1,29,4):
print (“person”, (n))

print ("Team 2 includes: ")
for n in range(2,29,4):
print (“person”, (n))

print ("Team 3 includes: ")
for n in range(3,29,4):
print (“person”, (n))

print ("Team 4 includes: ")
for n in range(4,29,4):
print (“person”, (n))

Here is an improved version of the above abortion of a solution. This is at least a little cleaner,

``````teamtxt = "Team"
persontxt = "includes person "
for n in range(1,29,4):
for a in range(1,5):
print (teamtxt, a, persontxt, n)
n+=1

``````

This question doesn’t state the size of the group, so it is infinite loop that crashes the program. gg.

person = 0

while(person >= 0):
person = person + 1
print("Person ", str(person), "is on team ", str(person % 4))

The size of the group is not important. The question is only what team will they be on? That is an easy ask, with a simple answer.

``````What is your number? N
You are on Team N % 4.``````

Consider this as a way to automat the process:

``````team_players = range(1,29)
for i in range(4):
Team = [num for num in team_players if num %4 == i]
print(Team)
``````