FAQ: Learn Python: Syntax - Modulo

This community-built FAQ covers the “Modulo” exercise from the lesson “Learn Python: Syntax”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Modulo

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

28 posts were split to a new topic: How is modulo used and how does it determine which team?

12 posts were split to a new topic: Food for thought question?

2 posts were merged into an existing topic: Food for thought question?

I’ve rewritten the exercise directions to be more clear:

1: You’re trying to divide a group of people who are standing in a line into four teams. Each person is assigned a number based on their position in the line. In addition, each of the four teams is assigned a unique number that serves as the unique identifier for that team. To determine which team number a person number is assigned to, one must compute person number modulo 4. You are assigned number 27. Calculate your team number (27 modulo 4), and store in my_team.

2: Print my_team to display the team number that you are assigned to.

3: Calculate and print the team number of the person on your left (person number 26.) Then calculate and print the team number of the person on your right (person number 28.)


Why does 4 % 27 return 4?

Twenty-seven into four is zero, remainder 4.

In long division, the next division would be 40 / 27.

If we play with the numbers that come up in long division (which is easiest done on paper with a pencil, btw) we inevitably stumble upon a common sequence in the decimal portion of the quotient. A repeating sequence.

>>> 4/27

Any way we start computing the quotient, we will end up with 148 somehow repeated, ad infinitum. All rational numbers share this tendency.

>>> 40/27

The remainder is 13.

>>> 13/27

Ignore the 5. It’s proven that this sequence never ends and always repeats. The 5 is due to rounding.

Oh, but we know 13 was not divisible because it was the remainder. We forget to multiply it by 10.

>>> 130/27

The remainder is 22.

>>> 220 / 27

Again, ignore the 9 as an artifact of rounding.

Because we know this a repeating and infinite sequence, there really isn’t much point to going any further with the division. But it’s been fun, hasn’t it?


Anytime we see a repeating sequence we may conclude that this is a rational number, also proved in maths. We’ll leave the reader to contribute that portion of this discussion.

1 Like