Practice makes perfect. 6.is_prime


<In what way does your code behave incorrectly? Include ALL error messages.>

File “python”, line 7
if x % n == 0:
IndentationError: expected an indented block
<What do you expect to happen instead?>
is:prime should tell you if x is a prime number

def is_prime(x):
  boop = True
  if x<2:
  	return False
  	for n in range(2,x-1):
    	if x % n == 0:
      	boop = False
    return boop


everything that should be in the for loop, needs additional indent:

for loop:
   code here needs more indent then for loop
   to place it inside the loop


The indentation of the posted code consists of a mixture of spaces and tabs.

For example, this line contains spaces followed by a tab …

    	if x % n == 0:

Within a given Python program, use one or the other, but not both spaces and tabs, for indentation. In the Codecademy environment, use two spaces for each level of indentation, and no tabs.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.