I get what Modulo is and how it is calculated, but I donât get why I would be on team number 3 if I was number 27. If I was number 27 and each team had 4, then I should be on team number 7 shouldnât I? The instructions seem to imply that my_team is equal to my team number. Instructions below:
Youâre trying to divide a group into four teams. All of you count off, and you get number 27.
1. Find out your team by computing 27 modulo 4. Save the value to my_team .
2. Print out my_team . What number team are you on?
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?
Yeah, itâs not teams of 4, itâs 4 teams, but you still need to know the total number to tell you anything. This is a poorly written exercise. I understand how modulo and division works. Just not why the question is phrased the way it is, as itâs impossible to answer. Iâve submitted a bug report.
Its not just the exercise that is poorly written. The whole lesson is.
âIf the number is divisible, then the result of the modulo operator will be 0.â
What does that even mean? Divisible by what? 5 /2 in python will still give you 2.5 so 5 is still divisible by 2 it wont just be an int.
âThe modulo operator is useful in programming when we want to perform an action every nth-time the code is run.â
How? wonât be that treated via a loop and an if statement?
Thank you guys, someone just explained me it last night and now I get the logics behind it. So I will leave in here an easy way of understanding the logics behind it as well as where I was mixing things up.
Basically I was thinking âHow can I know which team will I be if I dont know how many people we are in total?â. The division I was doing was, if for example we have 100 people, we divide them 100 by 4 and the first 25 people will go into group 1, the next 25 (from 26 until 50) into group 2, the next 25 (from 26 til 75) into group 3 and the remaining people into group 4.
The explanation I was given is that this calcultion should be based on logics, and always the most effective way of doing things is also the most simple of it. The way I was doing it needed an extra answer (total number of people) but the optimal way of doing it would be for example when in physical education class the teacher divides the students into teams. So letâs say 10 kids divided into 3 teams. The teacher wouldnt divide 10 by 3, many times he wouldnât even need to count the total number of kids. He would simply say: âYou go into team number one, now you, the next in line, go into team number 2, next one into team number 3, now you again into team number 1, next into team number 2, next one into team number 3, now you again into team number 1, next one into team number 2 and next one into team number 3⌠wait, thatâs 9 kids but there is one child remaining, so you go into team number 1â.
So again, the most effective way of doing something is usually the simple way, and by having to ask extra questions to be able to solve the problem you are already adding a degree of complication to it.
These were both written a bit confusing, but they make sense if you understand the math/syntax.
On your first example, when it says divisible, it means only divisible into integers/whole numbers. 5 % 2 = 2 + 2, modulo/remainder of 1. So even though technically you can do 5/2 and receive a float of 2.5, if you wanted to use the remainder for something, you could perform 5 % 2 to figure that out.
On your second example, itâs saying that if you wanted to run your program for example, 100 times, but you wanted it to take action every 5 times, you could check to see if your number is an even multiple of 5. Like so:
for x in 100: #what to do every time.
if x % 5 == 0: #what to do every 5th time
So since 20 % 5 == 0, when you get to the 20th iteration, it would run a command. Same at 25, 30, etc.
âdivide a group into four teamsâ is not equal â4 people in each teamâ. This question would made sense if it changed to â4 people in each groupâ. If so, you were in team 7: 27//4=6;27%4=3.
It DOES needs total people for the original question as you mention.
Youâre trying to divide a group into four teams. All of you count off, and you get number 27.
Find out your team by computing 27 modulo 4. Save the value to my_team .
Each group of four kids, taken in order of count off, will each be on a different team.
Not quite. Starting anywhere in the sequence, every fourth kid will be on the same team. There is no âevery 3rdâ or every 2nd. The whole thing revolves around division by 4. The remainder determines which team a player is on.
exactly - if one were to say every 3rd kid will be in team 3, that would suggest that kid-6 would be in team 3 (3;6;9;12;15;âŚ), however this is not true as we are working with 4 groups/teams (4;8;12;16;20;24;28;âŚ), therefore the correct statement would be, âevery 3rd kid within each grouping of 4 will be in team 3â i.e. kid 7 is in the second grouping of 4 and is representing the third âquartileâ/group, and is therefore in group 3.
Youâre trying to divide a group into four teams. All of you count off, and you get number 27.
âCount offâ means the first of the total amount of kids declares, 1, the second declares 2, so on and so forth. You are the 27th kid in a linear lineup of an unknown total of kids in a class, and the teacher has to make 4 groups. This exercise uses the modulo to spit out some remainder, and use that as your team number, Modulo will only ever spit out a finite number of results, but for this exercise, weâre merely calculating (your_number_in_the_line_of_children % four_teams). The total is irrelevant, the teacher is just doing a hilarious math hack that will ensure he only gets 4 potential modulo results for his set of kids, and can use the result of the above equation to assign each kid in the line with a team number.
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?
To determine this, I just copied my own formula that I just used for my own team:
#assign me a team number using the following equation with the modulo #operator and print the result (which is 3, because 27/4 is 6, remainder 3)
my_team = (27 % 4)
print(my_team)
#since we're just going to copy our formula for kids in the 26th slot and the #28th slot, I'll just define some variables like we did above and print the results #to determine their team number
kid_26 = (26 % 4)
kid_28 = (28 % 4)
print(kid_26, kid_28)
Thank you for this, Now I understand what the question means.
Iâm not a native English Speaker and I was stuck because of this.
Hopefully CodeCademy can take into consideration that lots of students wonât be natives and explain things like this with sentences instead of two words.
I believe this will make the learning experience better for everyone.
I am a native speaker and this exercise confused the heck out of me. The explanation lacked depth, and there is only one example to build off of. Tis a great waste of 30 minutes of my life XD.
LOL it finally clicked, First off 27 is your number out of a unknown number of people. An easy way to understand this is if it was worded as such: You are divided into 4 groups with an unknown amount of people. You are given number 27 out of X number of people which group were you assigned to? Which is group three. If at some point your number was 64 then you would be in group: 0, 0 is technically a number and part of the 4 groups 0,1,2 and 3. I hope this helps.