Skip to content

Instantly share code, notes, and snippets.

@PythonDotLand
Last active July 5, 2021 21:11
Show Gist options
  • Save PythonDotLand/5e17ee7763a890197c99128cf4fb90d4 to your computer and use it in GitHub Desktop.
Save PythonDotLand/5e17ee7763a890197c99128cf4fb90d4 to your computer and use it in GitHub Desktop.
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//x)
break
else:
# loop fell through without finding a factor
print(n, 'is a prime number')
@hoxmark
Copy link

hoxmark commented Jul 5, 2021

I just read your blogpost. Thanks for sharing.

I think you'll need to update this gist to indent your else clause and if statement.

like this:

for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print(n, 'equals', x, '*', n//x)
            break
    else:
        # loop fell through without finding a factor
        print(n, 'is a prime number')

Thanks for sharing, this was new to me. :)

@PythonDotLand
Copy link
Author

Thanks.. something went wrong with the copy/pasting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment