-3

I am new to Python. The following code confuses me and I don't understand properly how it works, especially the code block if num%x==0. Can anybody explain it?

num=int(input("Enter a number: "))
for x in range(2,num):
    if num%x==0:
        print("{} is not prime".format(num))
        break
else:
     print ("{} is prime".format(num))
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Please first read the python documentation before start to ask questions: https://docs.python.org/3/tutorial/introduction.html#numbers – Ronald Jun 28 '20 at 14:39
  • 2
    Duplicate: [What does the percentage sign mean in Python](https://stackoverflow.com/questions/961344/what-does-the-percentage-sign-mean-in-python) – khelwood Jun 28 '20 at 14:42

1 Answers1

1

% is the modulus operator. num % x returns the remainder when num is divided by x; thus, if num % x is zero then num is evenly divisible by x, there being no remainder after the division is performed.