Codecademy Forums

Food for thought question?

I’m not really sure what the last part:

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?

is asking in terms of “What are the numbers for all 4 teams?”. Is the desired values 6, 12, 18, 24? And I’m to write in 27%6? 27%12? But they’re the same, can I just get some clarification?

I wrote the following and I was able to hit next, but I don’t see how my answer was sufficient.

my_team=27%4
print(my_team)
person1=26%4
person2=28%4
teams=4%27
print(person1, person2, teams)

4 Likes

“What are the numbers for all 4 teams?”
What exactly is this asking? And given the explanation how do we code it?
Thanks.

4 Likes

What are all the MOD 1?

1 5 9 13 17 21 25 29

What are all the MOD 2?

2 6 10 14 18 22 26 30

What are all the MOD 3?

3 7 11 15 19 23 27 31

What are all the MOD 0?

4 8 12 16 20 24 28 32
2 Likes

Jimmy, the wording of the “food for thought portion” brought me to this thread and, subsequently, sent me on a quest to answer this question as well. It took awhile, but I finally got!

I made a variable for each team and then set it equal to an iteration that resulted in a new list of the elements from my original list that fit the condition I set. That is:

for each element in team_players where % 4 == 1, 2, 3, or 0 they were put on that respective team.
team_players = [1,2,3,4,…28]
I chose 1-28 since those were the numbers given in the exercise

Team 1 = [num for num in team_players if num %4 == 1]
T2: if num %4 == 2
T3: if num %4 == 3
T4: if num %4 == 0

I checked my work by comparing the team placement of 26, 27, and 28 when using the code below against the the new lists from the code above.

my_team= 27%4 --> 3
print(my_team + 1) --> 4
print(my_team - 1) --> 2

4 Likes

some ideas:
to create a range of numbers in python you can use the range() builtin, e.g.:
numbers = range(0,24)
to iterate through that list and do something with each number, you can use a for loop, e.g.:
for n in numbers:
# do something here

I think that with this algorithm I can know the team that corresponds to each kid.

# kid is the number of the kid
# mynumber_team is the number of the team that corresponds to the kid

if kid % 4 == 0
	mynumber_team=(kid-kid%4)/4
else
	mynumber_team=[(kid-kid%4)/4]+1

# thus if kid = 26 how kid%4 not is 0 then mynumber_team=[(kid-kid%4)/4]+1 --> mynumber_team=[(26-26%4)/4]+1 = 7
# thus if kid = 27 how kid%4 not is 0 then mynumber_team=[(kid-kid%4)/4]+1 --> mynumber_team=[(26-26%4)/4]+1 = 7
# thus if kid = 28 how kid%4 is 0 then mynumber_team=[(kid-kid%4)/4] --> mynumber_team=[(26-26%4)/4] = 7
1 Like

Some how only typing this let me pass the whole thing ?

print(27 % 4)
my_team = 3

I think this lesson is broken ? it even said this was the answer to what team 26 and and 28 were on … also weren’t there only 27 people ???

7 Likes

Question 3 was too ambiguous. I had to assume there were only 28 people total. That wasn’t explicitly stated, however. And given that up to now ever answer I’ve entered was in code form, it seemed odd to just type in numbers, but that seems what question 3 is asking for. This is what I entered for the answer (and got a checkmark, so assume I guess it was correct):

2
4
1, 5, 9, 13, 17, 21, 25
2, 6, 10, 14, 18, 22, 26
3, 7, 11, 15, 19, 23, 27
4, 8, 12, 16, 20, 24, 28

You did enter them correctly, and that is what counts. You clearly understand the modulo operator which is a great step forward.

which given the evidence, nothing suggests more, or less. You assumed correctly, and would have been ill advised to do otherwise. Great logic. The narrative is ambiguous, I’ll give you that.

A little silliness for levity…

>>> sorted(list(map(lambda x: ((x + 1) % 4 or 4, x + 1), range(28))))
[(1, 1), (1, 5), (1, 9), (1, 13), (1, 17), (1, 21), (1, 25), (2, 2), (2, 6), (2, 10), (2, 14), (2, 18), (2, 22), (2, 26), (3, 3), (3, 7), (3, 11), (3, 15), (3, 19), (3, 23), (3, 27), (4, 4), (4, 8), (4, 12), (4, 16), (4, 20), (4, 24), (4, 28)]
>>> 
2 Likes

You can just count to 28, putting each person on one of four teams:

Team 1 are persons [1, 5, 9, 13, 17, 21, 25]
Team 2 are persons [2, 6, 10, 14, 18, 22, 26]
Team 3 are persons [3, 7, 11, 15, 19, 23, 27] # that’s the team you are on!
Team 4 (actually team 0) are persons [4, 8, 12, 16, 20, 24, 28]

… or, you can code it:
(Say that there are 28 people.)

team = []
for i in range(4):
    team.append([])
for person in range(1, 29):
    for i in range(4):
        if person % 4 == i:
            team[i].append(person)

for i in range(4):
    print("Team {} are persons {}".format(i, team[i]))   
4 Likes

a = 27
b = 4

my_team = (a % 2)

print(my_team)

Did you mean to write,

my_team = a % b

?

I have been able to come up with this code for the 11th exercise and I got it right-

my_team = 27 % 4
print(my_team)

my team is 3 because 27/4 is 6 with a remainder of 3.

person_a = 26 % 4
person_b = 28 % 4
print(person_a)
print(person_b).

I come to understand that the teams are assigned base on remainders, but I don’t know how
to solve the next part which says “What are the numbers for all 4 teams?”, can someone help me out please?

It is a tricky exercise, but yes, the kid counted off as 27 falls into group 3, regardless the total number of kids. You don’t need to know the total number of kids, since you group them as they “count off”. It is position what it is discussed here, not numbers.

I think that many of us got confused by the meaning of “to count off” but if you read upwards in the comments, it is very well explained.

What group kid number 29 would fall into?. Clue: A post where the word MOD appears.

I used this:
my_team = 27 % 4
print(my_team)

Person_26 = my_team -1
print(Person_26)

Person_28 = my_team +1
print(Person_28)

We’re all in agreement that # 27 is on team 3, but if the teacher is actually using modular arithmetic unadorned with any little tricks, the next person is on team 0, not team 4, since adding 1 mod 4 gives 1,2,3, 0; 1, 2, 3, 0 …

1 Like

Hello fellow coder and thank you very much for this response. Everything makes much more sense now.
All i wanted to know is this; Did the question require the answer to be written as code or in simple text? Because nowhere in this section is taught how to write this as a code and I’m a little worried cause it feels like I’ve been left behind.

As far as I can tell, no response at all was required. You get a “magic green check mark” whether or not you write anything down at all!

Even so, the length of this thread shows that the question, for better or worse, was truly “food for thought.”

I think the third question is just giving you something to think about (“food for thought”) and not really a step you need to complete.

If you are asking which team each person is, try this:

person = 0

while(person < 28):
  person = person + 1
  print("Person ", str(person), "= Team ", str(person % 4))