ModularM
Modular3y ago
7 replies
Larsis

How to use Modulo?

This works print(10%) but I can't use % in a method:

def is_prime(n):
  for i in range(2,n):
    if (n%i) == 0:
      return False
  return True


How come I get the following error?

error: Expression [8]:7:10: 'object' does not implement the '__mod__' method
    if (n%i) == 0:
        ~^

expression failed to parse (no further compiler diagnostics)
Was this page helpful?