def prime_check(num):
"""
Function to check if a number is prime
"""
for n in range(2,num):
if num%n == 0:
print(num, "is not prime")
break
else:
print(num, "is not prime")
pardon me as i just started using stack over flow and i don't know how to show the syntax highlighting here. but looking at the code above, when i call the function and i pass in the integer (number 2) into the function, there is no result, also when i pass in the number 21, it says 21 is prime, which is wrong. however, when using the code from udemy, which is a bit similar to mine(except for indentation), the function works fine. i need help understanding the indentation difference and why it works. The udemy code is shown below.
def is_prime(num):
'''
Naive method of checking for primes.
'''
for n in range(2,num):
if num % n == 0:
print(num,'is not prime')
break
else: # If never mod zero, then prime
print(num,'is prime!')
notice the difference in indentation between my own code and theirs. Please i need to understand the difference. Help!!!!!!!!!!