Code example of Python Modulo Operator

39

# function is defined for finding out 
# the remainder of every number from 1 to n
def findRemainder(n, k):
    
  for i in range(1, n + 1):
    # rem will store the remainder 
    # when i is divided by k.
    rem = i % k  
    print(i, "mod", k, "=", rem, sep = " ")
  
# Driver code
if __name__ == "__main__" :
# inputs
  n = 10
  k = 7
# function calling
  findRemainder(n, k)
# inputs
a = 435
b = 23
  
# Stores the remainder obtained 
# when dividing a by b, in c
c = a % b      
print(a, "mod", b, "=", c, sep = " ")

Comments

Submit
0 Comments