0

So I just started learnig how to code and I've been studying from the guide on the official python website and I came across this subject but I don't quite understand how this code works can someone explain it to me please?

for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print(n, 'equals' , x, '*' , n//x)
            break
    else:
        print(n, 'is a prime number')

This loop searches for prime numbers

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
Seraph
  • 1
  • 1
  • This answer explains it https://stackoverflow.com/a/16451661/4727702 – Yevhen Kuzmovych Aug 22 '22 at 11:27
  • It is nested looping (for) if n modules x == 0 , mean even number, then the inner loop will break (terminated) and continue to the new loop else , will execute if the condition "if" in loop not met (n is odd) print(n, 'equals' , x, '*' , n//x) , show the output to terminal, console – Henro Sutrisno Tanjung Aug 22 '22 at 11:33

0 Answers0