Python 11 Modulo


#1

https://www.codecademy.com/paths/computer-science/tracks/cspath-intro/modules/cspath-python-syntax/lessons/learn-python-syntax/exercises/modulo

Ok, so I’m not getting most of this lesson. Here is my code, but past the first part of finding what team you’re on, I can’t seem to understand the rest of it. Help please

my_team = 27 % 4
print(my_team)
left_person = 26 % 4
right_person = 28 % 4
print(left_person)
print(right_person)


#2

The assumption made in this code, is that member 1 is in team 1, member 2 in team 2, member 3 in team 3, member in team 4, person 5 in team 1 and so on:

for i in range(1, 28):
  print("person: %d" % i, end=", ")
  team = i % 4
  if team == 0:
    print("team: 4")
  else:
    print("team: %d" % team)

the only problem is that numbers divisible by 4 given zero, so you would nee to tweak the code a little bit


#3

Thank you for your reply, I’m super new and the code you posted makes little to no sense to me. When the question asked how do you find the numbers for all teams, I’m assuming its asking to use modulo to do so, I don’t understand how that works.


#4

Have you run the code? See how i put everyone in a team? In the output of my code, see if you can find the pattern of how i put everyone inside a team. Once you get this “pattern”, we can talk about the modulo operator usage here